10 Replies - 813 Views - Last Post: 09 December 2009 - 01:43 PM Rate Topic: -----

#1 idon86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-November 09

compiler error

Posted 09 December 2009 - 03:03 AM

Hello everyone
I submitted my work to my teacher
But I received a score of zero because he claims that i have compiler error
In my computer there is no compiler error
Could someone please check what's wrong with my c code?
plz help me i am desperate....
i add to the post my file c code as text file

Attached File(s)


This post has been edited by idon86: 09 December 2009 - 03:22 AM

Is This A Good Question/Topic? 0
  • +

Replies To: compiler error

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: compiler error

Posted 09 December 2009 - 03:07 AM

That isn't C# code, it is C code.

This post has been edited by crepitus: 09 December 2009 - 03:07 AM

Was This Post Helpful? 0
  • +
  • -

#3 idon86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-November 09

Re: compiler error

Posted 09 December 2009 - 03:15 AM

View Postcrepitus, on 9 Dec, 2009 - 02:07 AM, said:

That isn't C# code, it is C code.

I fix it....
what about my question?
Was This Post Helpful? 0
  • +
  • -

#4 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: compiler error

Posted 09 December 2009 - 05:52 AM

I dont even know if you can do this with the new compilers
int ch[8][8]={0}

Here this about this while
while ((abc>4)||(abc<1))

its never gonna work, something bigger than 4 and less than 1 but your choices are 1 to 4 :P

Im guessing your looking for
while(abc <5 && abc >0)

ITS int main() NOT void main and this is C code :o

EDIT:
Havent checked but i noticed i made a mistake :P

in the while statement i didnt noticed that you are looking for bad selection so take no notice of that my bad

I compiled your code gave me no errors :o

This post has been edited by poncho4all: 09 December 2009 - 06:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: compiler error

Posted 09 December 2009 - 06:01 AM

Moved to C/C++ Forum.

Here's the code:

/* =========================================================
 *
 *
 *      Course :
 *     C Programming 
 *     Exercise 2
 *
 * Date: 25-nov-2009
 *
 * =========================================================
 * 1.  8 queens assignment
 * 2.  8 queens solution print
 * 3.  Check query
 * ========================================================= */ 

#include <stdio.h>

void main() 
{
	int ch[8][8]={0},p,j=0,i=0,tfalse=50,b,z=1,n,s,d,abc=0;  //initialize variables for the first program
	int i2,j2,temp2=0,ch2[8]={0},N2=1,flag=0,flag2=0,temp3=0,b2;  //initialize variables for the 2nd program
	int ch3[8][8]={0},j3=0,i3=0,tool3,b3=1,kj3,ki3,te3=0,check3=0;  //initialize variables for the third program


	while(abc!=4)
	{
		printf("1.  8 queens assignment\n2.  8 queens solution print\n3.  Check query\n4.  Exit program\nEnter your choice (1-4): ");
		scanf("%d" ,&abc);
		while ((abc>4)||(abc<1)){
			printf("Enter your choice <1-4>: ");
			scanf("%d" ,&abc);
		}
		printf("\n");
		
		switch (abc){

case 1:  /************here strat the first program****************/
	for (p=0;p<8;p++){
		printf ("Enter location of queen no. %d : ",p);
		scanf ("%d,%d",&i,&j);
		if ((i>7)||(i<0)||(j>7)||(j<0)){
			printf("Out of boundaries!\n");
			p=p-1;
		}
		if (ch[i][j]==3){
			printf ("Already taken!\n");
			p=p-1;
		}
		if ((ch[i][j]==0)&&((i<8)&&(i>=0)&&(j<8)&&(j>=0))){
			ch[i][j]=3;
		}
	}
	for(i=0;i<8;i++){
		for(j=0;j<7;j++){
			for (b=1;z<8;b++){
				if ((ch[i][j]==3)&&(ch[i][b+j]==3))	{
					tfalse=0;
				}
				z++;
			}
			}
		z=1;
	}
	for(i=0;i<8;i++){
		for(j=0;j<7;j++){
			for (b=1;z<8;b++){
				if (ch[i][j]==3&&ch[i+b][j]==3){
					tfalse=0;
				}
				z++;
			}
			}
		z=1;
	}
	for(i=0;i<8;i++){
		for(j=0;j<7;j++){
			for (b=1,n=1,s=1,d=1;z<8;b++,n++,s++,d++){
				if ((b+j)>7) break;
				if ((n+i)>7) break;
				if ((ch[i][j]==3&&ch[i+n][b+j]==3)){
					tfalse=0;
				}
				z++;
			}
			z=1;
		}
	}
	for(i=0;i<8;i++){
		for(j=0;j<8;j++){
			for (s=1,d=1;z<8;b++,n++,s++,d++){
				if ((i+s)>7) break;
				if ((j-d)<0) break;
				if ((ch[i][j]==3&&ch[i+s][j-d]==3)){
					tfalse=0;
				}
				z++;
			}
			z=1;
		}
	}

	if (!tfalse) {printf("Impossible assignment!\n\n");}
	if (tfalse) {printf("Possible assignment!\n\n");}
	
	for(i=0;i<8;i++){     //here the program ends and now initialize the variables
		for(j=0;j<8;j++){
			ch[i][j]=0;
		}
	}
	j=0;i=0;tfalse=50;z=1;
	
	break;

	case 2:                          /************here strat the 2nd program****************/
	printf("Enter solution number: ");
	scanf("%d",&N2);
	while ((N2>92)||(N2<1)){
	printf("Enter solution number: ");
	scanf("%d",&N2);
		}
	while (temp3!=N2){
	for (i2=0;i2<8;i2++){
			for (j2=0;j2<i2;j2++){        
				if (ch2[i2]+i2-j2==ch2[j2]){             //check the down Diagonal
			if(ch2[i2]+1<8){
				ch2[i2]++;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				flag=1;
			}
			else {
				ch2[i2]=0;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				ch2[i2-1]++;
				flag=1;
				if (ch2[i2-1]>7){
					ch2[i2-1]=0;
					ch2[i2-2]++;
					flag2=1;
				}
				j2=-1;
				flag2=1;
			}
		}
				if (ch2[j2]==ch2[i2]){     //check the Column
			if(ch2[i2]+1<8){
				ch2[i2]++;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				flag=1;
			}
			else {
				ch2[i2]=0;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				ch2[i2-1]++;
				flag=1;
				if (ch2[i2-1]>7){
					ch2[i2-1]=0;
					ch2[i2-2]++;
					flag2=1;
				}
				j2=-1;
				flag2=1;
			}
		}
				if ((ch2[i2]==ch2[j2]+i2-j2)&&(j2+1<8)){     //check the upper Diagonal
			if(ch2[i2]+1<8){
				ch2[i2]++;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				flag=1;
			}
			else {
				ch2[i2]=0;
				for(b2=1;b2<8;b2++){
					if(i2+b2<8) ch2[i2+b2]=0;
				}
				ch2[i2-1]++;
				flag=1;
				if (ch2[i2-1]>7){
					ch2[i2-1]=0;
					ch2[i2-2]++;
					flag2=1;
				}
				j2=-1;
			}
		}
if (flag){
	j2=-1;
	i2=0;
	flag=0;
}
		}
		if (ch2[7]!=0) temp2=1;
		if (flag2){
		i2=-1;
		flag2=0;
		}
	}
	temp3++;

	
	if (temp3==N2){
		for(i2=0;i2<8;i2++){
			printf("%d,%d ",i2,ch2[i2]);
	}
	printf("\n\n");
	}
		if(ch2[7]==7){
		ch2[7]=0;
		ch2[6]++;
	}
	else ch2[7]++;

	}


	for (b2=0;b2<8;b2++){      //here the program ends and now initialize the variables
		ch2[b2]=0;
	}
	temp2=0;N2=1;flag=0;flag2=0;temp3=0;

	break;


	case 3:                    /************here strat the third program****************/
		do{
			printf ("Enter row,column,tool: ");
			scanf ("%d,%d,%d",&i3,&j3,&tool3);
				if ((ch3[i3][j3]!=0)&&((i3<8)&&(i3>=0))&&((j3<8)&&(j3>=0))&&(tool3>0)&&(tool3<6)){
					printf ("Already taken!\n");
			}
			if (tool3==1){ki3=i3; kj3=j3;}         //remmber the king posion
			if ((ch3[i3][j3]==0)&&(i3<8&&(i3>=0)&&((j3<8)&&(j3>=0))&&((tool3<6)&&(tool3>0)))) ch3[i3][j3]=tool3;  //      
			}
		while ((i3<8&&(i3>=0)&&((j3<8)&&(j3>=0))&&((tool3<6)&&(tool3>0))));
		
		for(i3=0;i3<8;i3++){      
			for(j3=0;j3<8;j3++){
				if (ch3[i3][j3]==3){                  //algoritem for the "charich"
					for(b3=1;(j3+b3)<kj3;b3++){  
						if((ch3[i3][j3+b3]==0)){te3=te3+1;}
					}
					if ((kj3-j3-1==te3)&&(ki3==i3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(((j3-b3)>=0)&&(ch3[i3][j3-b3]!=1));b3++){     
						if((ch3[i3][j3-b3]==0)){te3=te3+1;}
					}
					if ((j3-kj3-1==te3)&&(ki3==i3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(i3+b3)<ki3;b3++){    
						if((ch3[i3+b3][j3]==0)){te3=te3+1;}
					}
					if ((ki3-i3-1==te3)&&(kj3==j3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(((i3-b3)>=0)&&(ch3[i3-b3][j3]!=1));b3++){          
						if((ch3[i3-b3][j3]==0)){te3=te3+1;}
					}
					if ((i3-ki3-1==te3)&&(kj3==j3)){
						check3=1;
					}
				}
				if (ch3[i3][j3]==2){                   //algoritem for the queen
					for(b3=1;(j3+b3)<kj3;b3++){  
						if((ch3[i3][j3+b3]==0)){te3=te3+1;}
					}
					if ((kj3-j3-1==te3)&&(ki3==i3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(((j3-b3)>=0)&&(ch3[i3][j3-b3]!=1));b3++){     
						if((ch3[i3][j3-b3]==0)){te3=te3+1;}
					}
					if ((j3-kj3-1==te3)&&(ki3==i3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(i3+b3)<ki3;b3++){    
						if((ch3[i3+b3][j3]==0)){te3=te3+1;}
					}
					if ((ki3-i3-1==te3)&&(kj3==j3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(((i3-b3)>=0)&&(ch3[i3-b3][j3]!=1));b3++){           
						if((ch3[i3-b3][j3]==0)){te3=te3+1;}
					}
					if ((i3-ki3-1==te3)&&(kj3==j3)){
						check3=1;
					}
					te3=0;
					for(b3=1;(j3+b3)<kj3;b3++){ 
						if((ch3[i3+b3][j3+b3]==0)){te3=te3+1;}
					}
					if ((kj3-j3-1==te3)&&(ki3==i3+te3+1)){
						check3=1;
					}
					te3=0;	
					for(b3=1;(j3-b3-kj3)>0;b3++){     
						if((ch3[i3-b3][j3-b3]==0)){te3=te3+1;}
					}
					if ((j3-kj3-1==te3)&&(ki3==i3-te3-1)){
						check3=1;						
					}   
					te3=0;
					for(b3=1;(i3+b3)<ki3;b3++){    
						if((ch3[i3+b3][j3-b3]==0)){te3=te3+1;}
					}
					if ((ki3-i3-1==te3)&&(kj3==j3-te3-1)){
						check3=1;
					}
					te3=0;
			    	for(b3=1;(((i3-b3)>=0)&&(ch3[i3-b3][j3+b3]!=1));b3++){           
						if((ch3[i3-b3][j3+b3]==0)){te3=te3+1;}
					}
					if ((i3-ki3-1==te3)&&(kj3==j3+1+te3)){
						check3=1;
					}
				}
				if (ch3[i3][j3]==5){                 //algoritem for the runner
					te3=0;
					for(b3=1;(j3+b3)<kj3;b3++){  
						if((ch3[i3+b3][j3+b3]==0)){te3=te3+1;}
					}
					if ((kj3-j3-1==te3)&&(ki3==i3+te3+1)){
						check3=1;
						}
					te3=0;
					for(b3=1;(j3-b3-kj3)>0;b3++){     
						if((ch3[i3-b3][j3-b3]==0)){te3=te3+1;}
					}
					if ((j3-kj3-1==te3)&&(ki3==i3-te3-1)){
						check3=1;
						}   
					te3=0;
					for(b3=1;(i3+b3)<ki3;b3++){     
						if((ch3[i3+b3][j3-b3]==0)){te3=te3+1;}
					}
					if ((ki3-i3-1==te3)&&(kj3==j3-te3-1)){
						check3=1;
					}
					te3=0;
					for(b3=1;(((i3-b3)>=0)&&(ch3[i3-b3][j3+b3]!=1));b3++){           
						if((ch3[i3-b3][j3+b3]==0)){te3=te3+1;}
					}
					if ((i3-ki3-1==te3)&&(kj3==j3+1+te3)){
						check3=1;
					}
				}
				if (ch3[i3][j3]==4){                   //algoritem for the horus
					if ((ch3[i3+1][j3+2]==1)){ 
						check3=1;
					}
					if ((ch3[i3+1][j3-2]==1)&&((j3-2)>=0)){ 
						check3=1;
						}
					if ((ch3[i3-1][j3+2]==1)&&((i3-1)>=0)){ 
						check3=1;
					}
					if (((ch3[i3-1][j3-2]==1)&&((i3-1)>=0))&&((j3-2)>=0)){ 
						check3=1;
					}
					if ((ch3[i3+2][j3+1]==1)){ 
						check3=1;
					}
					if ((ch3[i3+2][j3-1]==1)&&((j3-1)>=0)){ 
						check3=1;
					}
					if ((ch3[i3-2][j3+1]==1)&&((i3-2)>=0)){ 
						check3=1;
					}
					if ((ch3[i3-2][j3-1]==1)&&((i3-2)>=0)){ 
						check3=1;
					}
				}
 }
 }
 if (check3) printf("check!\n\n");
 else printf("no check!\n\n");
 
 for(i3=0;i3<8;i3++){      //here the program ends and now initialize the variables
	 for(j3=0;j3<8;j3++){
		 ch3[i3][j3]=0;}}
 j3=0;i3=0;b3=1;kj3=0;ki3=0;te3=0;check3=0;

		}      //end the switch

	}	

}

Was This Post Helpful? 0
  • +
  • -

#6 idon86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-November 09

Re: compiler error

Posted 09 December 2009 - 06:09 AM

View Postponcho4all, on 9 Dec, 2009 - 04:52 AM, said:

I dont even know if you can do this with the new compilers
int ch[8][8]={0}


Here this about this while
while ((abc>4)||(abc<1))


its never gonna work, something bigger than 4 and less than 1 but your choices are 1 to 4 :P

Im guessing your looking for
while(abc <5 && abc >0)


ITS int main() NOT void main and this is C code :o

ok but how u can explain in Microsoft Visual Studio 2008 there is no compiler error?
and u can see if there other things that can do error?
Was This Post Helpful? 0
  • +
  • -

#7 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 120
  • View blog
  • Posts: 710
  • Joined: 15-October 09

Re: compiler error

Posted 09 December 2009 - 06:26 AM

View PostJackOfAllTrades, on 9 Dec, 2009 - 12:01 PM, said:

Here's the code


After obfuscation of OP's code, right?!! :blink:
Was This Post Helpful? 0
  • +
  • -

#8 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: compiler error

Posted 09 December 2009 - 06:29 AM

Im guessing your teacher tested the problem and there might be a runtime error. Dunno i didnt had any Build errors.
Was This Post Helpful? 0
  • +
  • -

#9 idon86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-November 09

Re: compiler error

Posted 09 December 2009 - 07:34 AM

View Postponcho4all, on 9 Dec, 2009 - 04:52 AM, said:

I dont even know if you can do this with the new compilers
int ch[8][8]={0}

Here this about this while
while ((abc>4)||(abc<1))

its never gonna work, something bigger than 4 and less than 1 but your choices are 1 to 4 :P

Im guessing your looking for
while(abc <5 && abc >0)

ITS int main() NOT void main and this is C code :o

EDIT:
Havent checked but i noticed i made a mistake :P

in the while statement i didnt noticed that you are looking for bad selection so take no notice of that my bad

I compiled your code gave me no errors :o

so what can i do?!
you have any idiea why my teacher say so?
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: compiler error

Posted 09 December 2009 - 07:36 AM

As stated previously, main should return INT not VOID. Microsoft's compiler is forgiving for this code, but g c c with the warnings turned up yields a few:
g c c -Wall -pedantic -o error error.c
error.c:19: warning: return type of main is not int
error.c: In function main:
error.c:20: warning: missing braces around initializer
error.c:20: warning: (near initialization for ch[0])
error.c:20:59: warning: C++ style comments are not allowed in ISO C90
error.c:20:59: warning: (this will be reported only once per input file)
error.c:22: warning: missing braces around initializer
error.c:22: warning: (near initialization for ch3[0])



View Postidon86, on 9 Dec, 2009 - 09:34 AM, said:

so what can i do?!
you have any idiea why my teacher say so?


Here's a totally novel idea: ASK THE TEACHER!!!! :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#11 idon86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-November 09

Re: compiler error

Posted 09 December 2009 - 01:43 PM

View PostJackOfAllTrades, on 9 Dec, 2009 - 06:36 AM, said:

As stated previously, main should return INT not VOID. Microsoft's compiler is forgiving for this code, but g c c with the warnings turned up yields a few:
g c c -Wall -pedantic -o error error.c
error.c:19: warning: return type of ‘main’ is not ‘int’
error.c: In function ‘main’:
error.c:20: warning: missing braces around initializer
error.c:20: warning: (near initialization for ‘ch[0]’)
error.c:20:59: warning: C++ style comments are not allowed in ISO C90
error.c:20:59: warning: (this will be reported only once per input file)
error.c:22: warning: missing braces around initializer
error.c:22: warning: (near initialization for ‘ch3[0]’)



View Postidon86, on 9 Dec, 2009 - 09:34 AM, said:

so what can i do?!
you have any idiea why my teacher say so?


Here's a totally novel idea: ASK THE TEACHER!!!! :rolleyes:

First, thank you
second thing, about my teacher he is not really want to help
Third you can please write me the errors for the new code above:

Attached File(s)


This post has been edited by idon86: 09 December 2009 - 11:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1