Page 1 of 1

Things that produce compile error

Posted: Fri Sep 05, 2003 10:08 am
by Joseph Kurniawan
Commands I used and got compile error :
1. string.h ---> strrev, strcmpi
2. stdlib.h ----> ltoa, atol

In prob 530, this code:

[c]
#include<stdio.h>
long double n,k,sum,a[37][18],c;
void main(){
a[28][14]=40116600;
a[29][14]=77558760;
a[30][14]=145422675;a[30][15]=155117520;
a[31][13]=206253075;a[31][14]=265182525;a[31][15]=300540195;

a[32][13]=347373600;a[32][14]=471435600;a[32][15]=565722720;a[32][16]=601080390;

a[33][13]=573166440;a[33][14]=818809200;a[33][15]=1037158320;a[33][16]=1166803110;
a[34][13]=927983760;a[34][14]=1391975640;a[34][15]=1855967520;
a[35][13]=1476337800;
while(scanf("%Lf %Lf",&n,&k)==2){
if(n==0) break;
if(k>n/2) k=n-k;
if(k<2){
if(k==0) printf("1\n");
else printf("%.0Lf\n",n);
}
else{
if(n<2) printf("1\n");
else{
if(n<37){
if(a[n][k]) printf("%.0Lf\n",a[n][k]);
else{
for(sum=1,c=k;c>0;c--,n--) sum*=n;
for(;k>1;k--) sum/=k;
printf("%.0Lf\n",sum);
}
}
else{
for(sum=1,c=k;c>0;c--,n--) sum*=n;
for(;k>1;k--) sum/=k;
printf("%.0Lf\n",sum);
}
}
}
}
}

[/c]

The warning is:
01811213_24.c:23: array subscript is not an integer
01811213_24.c:23: array subscript is not an integer
01811213_24.c:3: warning: return type of `main' is not `int'

In prob 579 :

[c]
#include<stdio.h>
#include<string.h>
float h,m,n,angle;
char a[10];
void main(){
while(scanf("%s",&a)==1){
if(strcmp(a,"0:00")==0) break;
if(a[1]==':'){h=a[0]-48;m=2;}
else{h=(a[0]-48)*10+a[1]-48;m=3;}
m=(a[m]-48)*10+a[m+1]-48;
if(!m) angle=(12-h)*30;
else{
h=(h+1)*5;
angle=(60-m)/2;
if(m<h&&(h-m)*6<angle) angle-=((h-m)*6);
else{
if(m<h) m+=60;
angle+=((m-h)*6);
}
}
if(angle>180) angle=360-angle;
printf("%.3f\n",angle);
}
}

[/c]

gives me CE with the warning :
01832900_24.c: In function `main':
01832900_24.c:10: array subscript is not an integer
01832900_24.c:10: array subscript is not an integer
01832900_24.c:5: warning: return type of `main' is not `int'

What's wrong with those????
[/c]

Posted: Fri Sep 05, 2003 11:26 am
by Dominik Michniewski
You should use

int main(void) { }

as main function declaration ... judge and ANSI think, that main must return value....

Best regards
DM

Posted: Fri Sep 05, 2003 1:25 pm
by Russell John
Dominik Michniewski wrote:judge and ANSI think, that main must return value....
This is the problem that I always use to face when I first started to play with C...

Even I used to get this messge:
Warning: 0
Error: 0

:wink:

Posted: Fri Jun 03, 2005 11:27 am
by jakabjr
well, u use double type as index for an array.
that's a no-no. if u're sure the values are integer, u can cast, but carefull for overflow & precision.