7 Replies - 262 Views - Last Post: 02 March 2012 - 10:06 AM Rate Topic: -----

#1 vaizaren  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 13
  • Joined: 24-February 12

My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 04:53 AM

#include<stdio.h>
#include<string.h>
#define LIMIT 9
void prepField(int field[9][9]);
void showField(int field[9][9]);
int checkField(int field[9][9]);
int horizontal_check(int field[9][9]);
int vertical_check(int field[9][9]);
int three_sqr_check(int field[9][9]);
main()
{
    int field[9][9],x,y,option,option2,new_val;
    do
    {
        printf("\nThis is a program based on the game 'Sudoku'.\n[1]Play Game\n[2]Quit\n\nEnter decided choice:\t"); 
        scanf("%d",option);
        if(option==1)
        {
            prepField(field);
           	do
            {
    			showField(field);
    		    printf("\nEnter column then row of desired coordinates:\t");
    			scanf("%d %d",&x,&y);
    			while(x<1||x>9||y<1||y>9)
                {
    				printf("\n\nInvalid coordinates, please try again.\nEnter column then row of desired coordinates:\t");
    				scanf("%d %d",&x,&y);
    			}
    			printf("\nEnter desired value:\t");
    			scanf("%d",&new_val);
    			while (new_val<0||new_val>9)
                {
    			    printf("\nInvalid value, please try again.\nEnter desired value:\t");
    			    scanf("%d",&new_val);
                }		
    			field[y-1][x-1]=new_val;
            }while(checkField(field)==1);
            printf("\nCongratulations, you solved the Sudoku puzzle\n");
        }
        if(option==2)
        {
            printf("\nGoodbye.\n");
            exit(0);
        }
        printf("\nDo you want to run this program again?\n[1]Yes\n[2]No\n\n");
        scanf("%d",&option2);
    }while(option2==1);
}
void prepField(int field[9][9])
{
	FILE *fp;
	int x=0,y=0;
	fp=fopen("fp.txt","r");
	char n;
	while((n=getc(fp))!=EOF);
    {	
		if(n=='0'||n=='1'||n=='2'||n=='3'||n=='4'||n=='5'||n=='6'||n=='7'||n=='8'||n=='9')
        {
		    field[y][x]=atoi(&n);
		    x++;
		    if(x==9)
            {
			    y++;
			    x=0;
		    }
		}
	}
	fclose(fp);
}
void showField(int field[9][9])
{
    int x,y;
    printf("\t  1     2     3     4     5     6     7     8     9  \n\t______________________________________________________");
    for(y=0;y<LIMIT;y++)
    {
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++) 
       {
	        printf("     ");
		    if (x==2||x==5)
            {
                printf("|");
            }
	     	else 
            {
                printf(" ");
            }
	   }
	   printf("|\n\t%d  |",y+1);
	   for(x=0;x<LIMIT;x++)
       {
           if(field[y][x]==0)
           {
               printf("     ");
           }
		   else 
           {
               printf("  %d  ",field[y][x]);
           }
           if(x==2||x==5)
           {
               printf("|");
           }
	       else
           {
               printf(" ");
           }
	       if(x==8)
           {
               printf("|");
           }
	   }
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++)
       {
           if(y==2||y==5||y==8)
           {
               printf("_____");
           }
           else 
           {
               printf("     ");
           }
   	       if((y==2||y==5)&&(x==2||x==5))
           {
               printf("__|");
           }
		   else if((x==2||x==5)&&y<8)
           {
               printf("  |");
           }
		   else if((x==2||x==5)&&(y==8||y==2||y==5))
           {
               printf("__|");
           }
	   }
	   if (y==2||y==5||y==8)
       {
           printf("___|");
       }
	   else
       {
           printf("   |");
       }
    }
    printf("\n\n");
}
int checkField(int field[9][9])
{
	int check;
	check=horizontal_check(field)+vertical_check(field)+three_sqr_check(field);
	if(check>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}

int horizontal_check(int field[9][9])
{
	int x,y,a=0,hcount[10],i;
	for(y=0;y<LIMIT;y++)
    {
		for(i=0;i<10;i++)
        {
			hcount[i] = 0;
		}
	    for(x=0;x<LIMIT;x++)
        {
			switch(field[y][x])
            {
				case 1:	
                     hcount[1]++;
				     if(hcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     hcount[2]++;
				     if(hcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     hcount[3]++;
				     if(hcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     hcount[4]++;
				     if(hcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     hcount[5]++;
				     if(hcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     hcount[6]++;
				     if(hcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     hcount[7]++;
				     if(hcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     hcount[8]++;
				     if(hcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     hcount[9]++;
				     if(hcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int vertical_check(int field[9][9])
{
	int x,y,a=0,vcount[10],i;
	for(x=0;x<LIMIT;x++)
    {
		for(i=0;i<10;i++)
        {
			vcount[i] = 0;
		}
	    for(y=0;y<LIMIT;y++)
        {
			switch(field[y][x])
            {
				case 1:	
                     vcount[1]++;
				     if(vcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     vcount[2]++;
				     if(vcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     vcount[3]++;
				     if(vcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     vcount[4]++;
				     if(vcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     vcount[5]++;
				     if(vcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     vcount[6]++;
				     if(vcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     vcount[7]++;
				     if(vcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     vcount[8]++;
				     if(vcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     vcount[9]++;
				     if(vcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int three_sqr_check(int field[9][9])
{
	int x,y,q,w=0,i,a=0,count3[10];
	do
    {
		for(q=0;q<=6;q=q+3)
        {
			for(i=1;i<10;i++)
            {
				count3[i]=0;
			}
			for(y=w;y<w+3;y++)
            {
				for(x=q;x<q+3;x++)
                {
					switch(field[y][x])
                    {
					    case 1:		
                            count3[1]++;
						    if(count3[1]>1)
                            {
                                a++;
                            }
				            break;
                        case 2:		
                            count3[2]++;
						    if(count3[2]>1)
                            {
                                a++;
                            }
				            break;
                        case 3:		
                            count3[3]++;
						    if(count3[3]>1)
                            {
                                a++;
                            }
				            break;
                        case 4:		
                            count3[4]++;
						    if(count3[4]>1)
                            {
                                a++;
                            }
				            break;
                        case 5:		
                            count3[5]++;
						    if(count3[5]>1)
                            {
                                a++;
                            }
				            break;
				        case 6:		
                            count3[6]++;
						    if(count3[6]>1)
                            {
                                a++;
                            }
                            break;
				        case 7:		
                            count3[7]++;
						    if(count3[7]>1)
                            {
                                a++;
                            }
				            break;
                        case 8:		
                            count3[8]++;
						    if(count3[8]>1)
                            {
                                a++;
                            }
				            break;
				        case 9:		
                            count3[9]++;
						    if(count3[9]>1)
                            {
                                a++;
                            }
				            break;
                    }
                }
            }
			if(q=6)
            {
                w=w+3;
            }
        }
    }while(w!=9);
	if(a>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}


i think the problem here is on prepField function or showField function, i just cant find it, but to you guys, what's wrong in this codE? btw, this is sudoku and it needs the user to create a txt file named fp.txt with the default numbers in a sudoku. 0 means blank.

Is This A Good Question/Topic? 0
  • +

Replies To: My option 1, play game, is selected, , it does print nothing

#2 vaizaren  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 13
  • Joined: 24-February 12

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 05:08 AM

there is no problem in showField, it runs very well., the problem is in prepField, but what is it? can someone help mE?

new code
#include<stdio.h>
#include<string.h>
#define LIMIT 9
void prepField(int field[9][9]);
void showField(int field[9][9]);
int checkField(int field[9][9]);
int horizontal_check(int field[9][9]);
int vertical_check(int field[9][9]);
int three_sqr_check(int field[9][9]);
main()
{
    int field[9][9],x,y,option,option2,new_val;
    do
    {
        prepField(field);
        showField(field);
        printf("\nThis is a program based on the game 'Sudoku'.\n[1]Play Game\n[2]Quit\n\nEnter decided choice:\t"); 
        scanf("%d",option);
        if(option==1)
        {
            prepField(field);
           	do
            {
    			showField(field);
    		    printf("\nEnter column then row of desired coordinates:\t");
    			scanf("%d %d",&x,&y);
    			while(x<1||x>9||y<1||y>9)
                {
    				printf("\n\nInvalid coordinates, please try again.\nEnter column then row of desired coordinates:\t");
    				scanf("%d %d",&x,&y);
    			}
    			printf("\nEnter desired value:\t");
    			scanf("%d",&new_val);
    			while (new_val<0||new_val>9)
                {
    			    printf("\nInvalid value, please try again.\nEnter desired value:\t");
    			    scanf("%d",&new_val);
                }		
    			field[y-1][x-1]=new_val;
            }while(checkField(field)==1);
            printf("\nCongratulations, you solved the Sudoku puzzle\n");
        }
        if(option==2)
        {
            printf("\nGoodbye.\n");
        }
        printf("\nDo you want to run this program again?\n[1]Yes\n[2]No\n\n");
        scanf("%d",&option2);
    }while(option2==1);
}
void prepField(int field[9][9])
{
	FILE *fp;
	int x=0,y=0;
	fp=fopen("fp.txt","r");
	char n;
	while((n=getc(fp))!=EOF);
    {	
		if(n=='0'||n=='1'||n=='2'||n=='3'||n=='4'||n=='5'||n=='6'||n=='7'||n=='8'||n=='9')
        {
		    field[y][x]=atoi(&n);
		    x++;
		    if(x==9)
            {
			    y++;
			    x=0;
		    }
		}
	}
	fclose(fp);
}
void showField(int field[9][9])
{
    int x,y;
    printf("\t      1     2     3     4     5     6     7     8     9  \n\t    ______________________________________________________");
    for(y=0;y<LIMIT;y++)
    {
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++) 
       {
	        printf("     ");
		    if (x==2||x==5)
            {
                printf("|");
            }
	     	else 
            {
                printf(" ");
            }
	   }
	   printf("|\n\t%d  |",y+1);
	   for(x=0;x<LIMIT;x++)
       {
           if(field[y][x]==0)
           {
               printf("     ");
           }
		   else 
           {
               printf("  %d  ",field[y][x]);
           }
           if(x==2||x==5)
           {
               printf("|");
           }
	       else
           {
               printf(" ");
           }
	       if(x==8)
           {
               printf("|");
           }
	   }
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++)
       {
           if(y==2||y==5||y==8)
           {
               printf("_____");
           }
           else 
           {
               printf("     ");
           }
   	       if((y==2||y==5)&&(x==2||x==5))
           {
               printf("__|");
           }
		   else if((x==2||x==5)&&y<8)
           {
               printf("  |");
           }
		   else if((x==2||x==5)&&(y==8||y==2||y==5))
           {
               printf("__|");
           }
	   }
	   if (y==2||y==5||y==8)
       {
           printf("___|");
       }
	   else
       {
           printf("   |");
       }
    }
    printf("\n\n");
}
int checkField(int field[9][9])
{
	int check;
	check=horizontal_check(field)+vertical_check(field)+three_sqr_check(field);
	if(check>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}

int horizontal_check(int field[9][9])
{
	int x,y,a=0,hcount[10],i;
	for(y=0;y<LIMIT;y++)
    {
		for(i=0;i<10;i++)
        {
			hcount[i] = 0;
		}
	    for(x=0;x<LIMIT;x++)
        {
			switch(field[y][x])
            {
				case 1:	
                     hcount[1]++;
				     if(hcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     hcount[2]++;
				     if(hcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     hcount[3]++;
				     if(hcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     hcount[4]++;
				     if(hcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     hcount[5]++;
				     if(hcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     hcount[6]++;
				     if(hcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     hcount[7]++;
				     if(hcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     hcount[8]++;
				     if(hcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     hcount[9]++;
				     if(hcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int vertical_check(int field[9][9])
{
	int x,y,a=0,vcount[10],i;
	for(x=0;x<LIMIT;x++)
    {
		for(i=0;i<10;i++)
        {
			vcount[i] = 0;
		}
	    for(y=0;y<LIMIT;y++)
        {
			switch(field[y][x])
            {
				case 1:	
                     vcount[1]++;
				     if(vcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     vcount[2]++;
				     if(vcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     vcount[3]++;
				     if(vcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     vcount[4]++;
				     if(vcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     vcount[5]++;
				     if(vcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     vcount[6]++;
				     if(vcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     vcount[7]++;
				     if(vcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     vcount[8]++;
				     if(vcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     vcount[9]++;
				     if(vcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int three_sqr_check(int field[9][9])
{
	int x,y,q,w=0,i,a=0,count3[10];
	do
    {
		for(q=0;q<=6;q=q+3)
        {
			for(i=1;i<10;i++)
            {
				count3[i]=0;
			}
			for(y=w;y<w+3;y++)
            {
				for(x=q;x<q+3;x++)
                {
					switch(field[y][x])
                    {
					    case 1:		
                            count3[1]++;
						    if(count3[1]>1)
                            {
                                a++;
                            }
				            break;
                        case 2:		
                            count3[2]++;
						    if(count3[2]>1)
                            {
                                a++;
                            }
				            break;
                        case 3:		
                            count3[3]++;
						    if(count3[3]>1)
                            {
                                a++;
                            }
				            break;
                        case 4:		
                            count3[4]++;
						    if(count3[4]>1)
                            {
                                a++;
                            }
				            break;
                        case 5:		
                            count3[5]++;
						    if(count3[5]>1)
                            {
                                a++;
                            }
				            break;
				        case 6:		
                            count3[6]++;
						    if(count3[6]>1)
                            {
                                a++;
                            }
                            break;
				        case 7:		
                            count3[7]++;
						    if(count3[7]>1)
                            {
                                a++;
                            }
				            break;
                        case 8:		
                            count3[8]++;
						    if(count3[8]>1)
                            {
                                a++;
                            }
				            break;
				        case 9:		
                            count3[9]++;
						    if(count3[9]>1)
                            {
                                a++;
                            }
				            break;
                    }
                }
            }
			if(q=6)
            {
                w=w+3;
            }
        }
    }while(w!=9);
	if(a>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}


Was This Post Helpful? 0
  • +
  • -

#3 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 05:09 AM

On line 16 your getting a segfault. It needs to be scanf("%d",&option); you're missing the '&'.

You should also check the file opened successfully on line 54, by checking the pointer is not NULL.

This post has been edited by simeesta: 01 March 2012 - 05:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 vaizaren  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 13
  • Joined: 24-February 12

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 05:27 AM

#include<stdio.h>
#include<string.h>
#define LIMIT 9
void prepField(int field[9][9]);
void showField(int field[9][9]);
int checkField(int field[9][9]);
int horizontal_check(int field[9][9]);
int vertical_check(int field[9][9]);
int three_sqr_check(int field[9][9]);
main()
{
    int field[9][9],x,y,option,option2,new_val;
    do
    {
        printf("\nThis is a program based on the game 'Sudoku'.\n[1]Play Game\n[2]Quit\n\nEnter decided choice:\t"); 
        scanf("%d",&option);
        if(option==1)
        {
            prepField(field);
           	do
            {
    			showField(field);
    		    printf("\nEnter column then row of desired coordinates:\t");
    			scanf("%d %d",&x,&y);
    			while(x<1||x>9||y<1||y>9)
                {
    				printf("\n\nInvalid coordinates, please try again.\nEnter column then row of desired coordinates:\t");
    				scanf("%d %d",&x,&y);
    			}
    			printf("\nEnter desired value:\t");
    			scanf("%d",&new_val);
    			while (new_val<0||new_val>9)
                {
    			    printf("\nInvalid value, please try again.\nEnter desired value:\t");
    			    scanf("%d",&new_val);
                }		
    			field[y-1][x-1]=new_val;
            }while(checkField(field)==1);
            printf("\nCongratulations, you solved the Sudoku puzzle\n");
        }
        if(option==2)
        {
            printf("\nGoodbye.\n");
        }
        printf("\nDo you want to run this program again?\n[1]Yes\n[2]No\n\n");
        scanf("%d",&option2);
    }while(option2==1);
}
void prepField(int field[9][9])
{
	FILE *fp;
	int x=0,y=0;
	char c;
	fp=fopen("fp.txt","r");
	while((c=getc(fp))!=EOF);
    {	
		if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9')
        {
		    field[y][x]=atoi(&c);
		    x++;
		    if(x==9)
            {
			    y++;
			    x=0;
		    }
		}
	}
	fclose(fp);
}
void showField(int field[9][9])
{
    int x,y;
    printf("\n\n\t      1     2     3     4     5     6     7     8     9  \n\t    ______________________________________________________");
    for(y=0;y<LIMIT;y++)
    {
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++) 
       {
	        printf("     ");
		    if (x==2||x==5)
            {
                printf("|");
            }
	     	else 
            {
                printf(" ");
            }
	   }
	   printf("|\n\t%d  |",y+1);
	   for(x=0;x<LIMIT;x++)
       {
           if(field[y][x]==0)
           {
               printf("     ");
           }
		   else 
           {
               printf("  %d  ",field[y][x]);
           }
           if(x==2||x==5)
           {
               printf("|");
           }
	       else
           {
               printf(" ");
           }
	       if(x==8)
           {
               printf("|");
           }
	   }
	   printf("\n\t   |");
	   for(x=0;x<LIMIT;x++)
       {
           if(y==2||y==5||y==8)
           {
               printf("_____");
           }
           else 
           {
               printf("     ");
           }
   	       if((y==2||y==5)&&(x==2||x==5))
           {
               printf("__|");
           }
		   else if((x==2||x==5)&&y<8)
           {
               printf("  |");
           }
		   else if((x==2||x==5)&&(y==8||y==2||y==5))
           {
               printf("__|");
           }
	   }
	   if (y==2||y==5||y==8)
       {
           printf("___|");
       }
	   else
       {
           printf("   |");
       }
    }
    printf("\n\n");
}
int checkField(int field[9][9])
{
	int check;
	check=horizontal_check(field)+vertical_check(field)+three_sqr_check(field);
	if(check>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}

int horizontal_check(int field[9][9])
{
	int x,y,a=0,hcount[10],i;
	for(y=0;y<LIMIT;y++)
    {
		for(i=0;i<10;i++)
        {
			hcount[i] = 0;
		}
	    for(x=0;x<LIMIT;x++)
        {
			switch(field[y][x])
            {
				case 1:	
                     hcount[1]++;
				     if(hcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     hcount[2]++;
				     if(hcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     hcount[3]++;
				     if(hcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     hcount[4]++;
				     if(hcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     hcount[5]++;
				     if(hcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     hcount[6]++;
				     if(hcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     hcount[7]++;
				     if(hcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     hcount[8]++;
				     if(hcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     hcount[9]++;
				     if(hcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int vertical_check(int field[9][9])
{
	int x,y,a=0,vcount[10],i;
	for(x=0;x<LIMIT;x++)
    {
		for(i=0;i<10;i++)
        {
			vcount[i] = 0;
		}
	    for(y=0;y<LIMIT;y++)
        {
			switch(field[y][x])
            {
				case 1:	
                     vcount[1]++;
				     if(vcount[1]>1)
                     {
                         a++;
                     }
					 break;
			    case 2:	
                     vcount[2]++;
				     if(vcount[2]>1)
                     {
                         a++;
                     }
					 break;
				case 3:	
                     vcount[3]++;
				     if(vcount[3]>1)
                     {
                         a++;
                     }
					 break;
			    case 4:	
                     vcount[4]++;
				     if(vcount[4]>1)
                     {
                         a++;
                     }
					 break;
                case 5:	
                     vcount[5]++;
				     if(vcount[5]>1)
                     {
                         a++;
                     }
					 break;
                case 6:	
                     vcount[6]++;
				     if(vcount[6]>1)
                     {
                         a++;
                     }
					 break;
                case 7:	
                     vcount[7]++;
				     if(vcount[7]>1)
                     {
                         a++;
                     }
					 break;
                case 8:	
                     vcount[8]++;
				     if(vcount[8]>1)
                     {
                         a++;
                     }
					 break;
                case 9:	
                     vcount[9]++;
				     if(vcount[9]>1)
                     {
                         a++;
                     }
					 break;
				default:
                     a++;
			}
	    }
	}
	if(a>0)
    {
        return 1;
    }
	else 
    {
        return 0;
    }
}
int three_sqr_check(int field[9][9])
{
	int x,y,q,w=0,i,a=0,count3[10];
	do
    {
		for(q=0;q<=6;q=q+3)
        {
			for(i=1;i<10;i++)
            {
				count3[i]=0;
			}
			for(y=w;y<w+3;y++)
            {
				for(x=q;x<q+3;x++)
                {
					switch(field[y][x])
                    {
					    case 1:		
                            count3[1]++;
						    if(count3[1]>1)
                            {
                                a++;
                            }
				            break;
                        case 2:		
                            count3[2]++;
						    if(count3[2]>1)
                            {
                                a++;
                            }
				            break;
                        case 3:		
                            count3[3]++;
						    if(count3[3]>1)
                            {
                                a++;
                            }
				            break;
                        case 4:		
                            count3[4]++;
						    if(count3[4]>1)
                            {
                                a++;
                            }
				            break;
                        case 5:		
                            count3[5]++;
						    if(count3[5]>1)
                            {
                                a++;
                            }
				            break;
				        case 6:		
                            count3[6]++;
						    if(count3[6]>1)
                            {
                                a++;
                            }
                            break;
				        case 7:		
                            count3[7]++;
						    if(count3[7]>1)
                            {
                                a++;
                            }
				            break;
                        case 8:		
                            count3[8]++;
						    if(count3[8]>1)
                            {
                                a++;
                            }
				            break;
				        case 9:		
                            count3[9]++;
						    if(count3[9]>1)
                            {
                                a++;
                            }
				            break;
                    }
                }
            }
			if(q=6)
            {
                w=w+3;
            }
        }
    }while(w!=9);
	if(a>0)
    {
        return 1;
    }
	else
    {
        return 0;
    }
}



this is the edited code, can you try this at your compilers people and tell me if id does right..
here is the inside of fp.txt

039846257
845279613
627513849
356124798
712985364
984637521
261398475
493752186
578461932

this txt file and code must be in the same directory

because in mine, i think it didnt successfully opened and get the data from the txt file..

View Postsimeesta, on 01 March 2012 - 05:09 AM, said:

You should also check the file opened successfully on line 54, by checking the pointer is not NULL.

how can i do it simeesta? can you show me how,?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 05:34 AM

Quote

because in mine, i think it didnt successfully opened and get the data from the txt file..


Well then, you can check that by making sure fp is not NULL after this call:
fp=fopen("fp.txt","r");


Learn to use error checking.
Was This Post Helpful? 0
  • +
  • -

#6 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 05:37 AM

atoi works on strings, not characters. To convert the character '0' to 0 subtract '0'. Works for all digits '1' ... '9'.
Was This Post Helpful? 0
  • +
  • -

#7 vaizaren  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 13
  • Joined: 24-February 12

Re: My option 1, play game, is selected, , it does print nothing

Posted 01 March 2012 - 06:24 PM

View Postsimeesta, on 01 March 2012 - 05:37 AM, said:

atoi works on strings, not characters. To convert the character '0' to 0 subtract '0'. Works for all digits '1' ... '9'.

can you show me how sir?
Was This Post Helpful? 0
  • +
  • -

#8 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: My option 1, play game, is selected, , it does print nothing

Posted 02 March 2012 - 10:06 AM

It's not difficult

char x = '6';
int val = x - '0'; //val is 6


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1