Input During Debug Session

Discussion in 'Mac Programming' started by ketema@ketema.n, Mar 27, 2005.

  1. macrumors newbie

    Joined:
    Mar 26, 2005
    #1
    Hello All, I'm new to Xcode, and I need help understanding how to get input from the keyboard to be accepted during a debug run. Currently I start a debug session, the debug window comes up fine. I also open the console window, and the program runs showing a prompt for input. When I type into the console window and press enter/return nothing happens. The program does not continue, it just sits there like it has not received anything. Can someone plese instruct me on the proper way to input during a debug session? Thank You.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Can you post the code you are currently using? Do you have any breakpoints set before reading the input?
     
  3. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    OK, this code works for me. You need to hit return to cause the code to read though... (note program never terminates, you'll need to kill it)

    Code:
    #include <stdio.h>
    
    int main (int argc, const char * argv[]) {
    	char c;
    	while (c=getc(stdin))
    	{
    		printf("%c",c);
    	}
        return 0;
    }
    
     
  4. thread starter macrumors newbie

    Joined:
    Mar 26, 2005
    #4
    #include <stdio.h>
    #define FLUSH while(getchar() != '\n'); //Little function to clear the stdin buffer
    int main (int argc, const char * argv[]) {
    int numRecords = 0;
    do{
    printf("How many records do you have?\t");
    if ( scanf("%d", &numRecords) ) {
    FLUSH
    }
    else {
    printf("Invalid input.\n");
    FLUSH
    }
    }while(numRecords == 0);
    ...rest of prog
    }

    program runs fine when built and running in a normal console, but in the debug console it prints the prompt, but neveer moves past that no matter what I type in....
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    OK minor alteration of what I wrote above to use scanf as you are.

    Code:
    #include <stdio.h>
    
    int main (int argc, const char * argv[]) {
    	int d;
        // insert code here...
    	while (scanf("%d",&d))
    	{
    		printf("%d",d);
    	}
        return 0;
    }
    
    This works fine for me in run mode in XCode. I still need to hit return to have the input read by the program.
     
  6. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    OK found out what you're problem is. In normal run mode (not debug) mode XCode opens a window called "Run Log" that you can type into which works with this. In debug mode it doesn't work. The Debugger Console Window does not work either. But if you go Debugger->Standard I/O Log (from the menu) you will get yet another window titled Debugger Console which does work in debug mode!
     
  7. thread starter macrumors newbie

    Joined:
    Mar 26, 2005
    #7
    Got it! That works fine. Thanks...to many windows though....
     

Share This Page