Thread: undetected problem

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    65

    undetected problem

    Code:
    it compiles but im really unable to find the problem
    
    int already_guessed(char dothenta[ALPHABET], char *letter ){
    	int i;
    		printf("You have guessed that. Give me a new letter:");
    		putchar('{');
    		for(i=0;i<ALPHABET && dothenta[i]!=' ';i++)
    			printf(" %c ",dothenta[i]);
    		putchar('}');
    		scanf("%c",*&letter);
    	return 1;
    
    }
    char  ekt_arith_kai_diav(int counter,char dothenta[ALPHABET]){
    	char letter;
    	int i;
    		printf("Give me a letter { ");						
    		for(i=0;i<counter && dothenta[i]!='\0';i++)
    		  printf("%c",dothenta[i]);
    		putchar('}');
    		scanf("%c",&letter);
    		putchar('\n');
    	return letter;
    			
    }
    void print_word(int thesi, char Dict[MaxWords][MaxWordLen],char guess[30]){
    	int i;
    		printf("The word is: ");
    		for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
    			guess[i]=('-');
    		for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
    			printf("%c",guess[i]);
    		putchar('\n');
    
    }	
    
    switch (choice){
            
            case 1:		counter=0;
    			thesi=Random(0,NumWords,&seed);			
    			print_word(thesi,Dict,guess);	//tiponi leksi
    			for (i=0;i<ALPHABET;i++)		
    				dothenta[i]='\0';	//arxikopoihsi
    			alaxe=0;
    		do{
    			if (!already_answered)
    			  letter=ekt_arith_kai_diav(counter,dothenta);
    			do{
    			  for(i=0;i<=counter && dothenta[i]!='\0';i++)
    			    if ( letter!=dothenta[i] )
    				mem=1;						
    			else{ 	
    			    mem=0;
    			    already_answered=already_guessed(dothenta,&letter);
    			    break;
    			 }
    		       	}while(!mem);
    			dothenta[counter]=letter;
    			counter++;
    			for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
    				if (Dict[thesi][i]==letter){
    			          guess[i]=letter;
    				  alaxe=1;
    			       }
    				 if(!alaxe)		
    					fail++;
    				vrike=elenx_an_vrike_leksi(Dict,guess,thesi);
    			if (vrike){
    				you_have++;
    				 WellDoneMsg();
    			}
    			else if (fail==7){
    				 i_have++;
    				 SorryMsg(Dict[thesi]);
    			   }
    		}while(fail!=7 && !vrike);
    break;
    
    
    i didnt put the other functions because there were already made my the teacher
    what the problem is?
    when im choosing the first option (case 1)
    it shows 
    Give me a letter { }
    Give me a letter { 
    }
    than Give me a letter { } and to wait for my answer

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    65
    noone?

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Seems like you have data in the input buffer that's leftover from a previous input operation... probably a stray newline that you need to get rid of. If the previous input operation was something like a scanf with a %d format specifier, then the trailing newline is very much likely still in the input buffer and when your code gets to that scanf("%c",&letter) part, it read the newline and continues on with the rest of the code without stopping to let you enter the letter. You need to clear the input buffer of that whitespace and the easiest way of doing that is to put a space in front of the %c in that scanf call. The space tells the scanf to ignore leading whitespace.
    Code:
    char  ekt_arith_kai_diav(int counter,char dothenta[ALPHABET]){
        char letter;
        int i;
        printf("Give me a letter { ");						
        for(i=0;i<counter && dothenta[i]!='\0';i++)
            printf("%c",dothenta[i]);
        putchar('}');
        scanf(" %c",&letter);  /* Notice the space */
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  2. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM
  5. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 10:40 PM

Tags for this Thread