Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ketema@ketema.n

macrumors newbie
Original poster
Mar 26, 2005
8
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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;
}
 

ketema@ketema.n

macrumors newbie
Original poster
Mar 26, 2005
8
0
#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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.