PDA

View Full Version : Input During Debug Session




ketema@ketema.n
Mar 27, 2005, 03:10 PM
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.



robbieduncan
Mar 27, 2005, 03:22 PM
Can you post the code you are currently using? Do you have any breakpoints set before reading the input?

robbieduncan
Mar 27, 2005, 03:31 PM
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)


#include <stdio.h>

int main (int argc, const char * argv[]) {
char c;
while (c=getc(stdin))
{
printf("%c",c);
}
return 0;
}

ketema@ketema.n
Mar 27, 2005, 03:41 PM
#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....

robbieduncan
Mar 27, 2005, 03:49 PM
OK minor alteration of what I wrote above to use scanf as you are.


#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.

robbieduncan
Mar 27, 2005, 03:52 PM
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!

ketema@ketema.n
Mar 27, 2005, 04:00 PM
Got it! That works fine. Thanks...to many windows though....