Things that produce compile error

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Things that produce compile error

Post 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]
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post 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
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Russell John
New poster
Posts: 40
Joined: Mon Jul 21, 2003 9:21 am
Location: Planet Earth
Contact:

Post 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:
1024 Programmer's Lane,
Algorithm City, United States of C++,
Planet Earth.
jakabjr
Learning poster
Posts: 56
Joined: Wed Mar 23, 2005 9:21 pm
Location: Timisoara, Romania

Post 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.
Understanding a problem in a natural way will lead to a natural solution
Post Reply

Return to “C”