Thread: looping do while

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    looping do while

    Hey guys im having trouble returning to the top of the do while loop if an invalid entry is been entered.. It keeps falling out could someone help me please?


    Code:
    #define FALSE 0
    #define TRUE  1
    
    do
      {
            fgets(buff, BUFF_SIZE, stdin);
            *month = atoi(buff); /** ascii to integer conversion**/
           
    	if(*month >0 && *month <12)
    	{
    	   printf("Valid month entry\n");
    	   return TRUE;
    	}
    	else
    	{
    	   printf("Invalid month entry\n");
    	   return FALSE;
    	}
         
    	printf("dude");
           /* getting rid of the newline char the enter key when
    	   running the program*/
    	   
    	/*locate newline in buff [a][b][\n]*/ 
    	
    	/**month = strlen(buff) -1;*/
    	
    	/* check if it is a newline char*/
    	
    	 /*if(buff[*month] == '\n') 
    	 {
    	   buff[*month] = '\0'; 
    	 }  */
    	 /* change it to null end of array[a][b][\0]*/
    	                    
    	
           
       }
       while(*month<0 && *month>12);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Post the code you tried, without half of it being commented out.

    I see a lot of *month being dereferenced, but without any context to it, for all I know you're just trashing uninitialised pointers.

    > It keeps falling out could someone help me please?
    Well you never get there anyway
    Both your if and else contain return, so there's no way you're executing the rest of the code no matter what you do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 06:03 AM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM