Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 27, 2005, 03:10 PM   #1
ketema@ketema.n
macrumors newbie
 
Join Date: Mar 2005
Input During Debug Session

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.
ketema@ketema.n is offline   0 Reply With Quote
Old Mar 27, 2005, 03:22 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Can you post the code you are currently using? Do you have any breakpoints set before reading the input?
robbieduncan is offline   0 Reply With Quote
Old Mar 27, 2005, 03:31 PM   #3
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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;
}
robbieduncan is offline   0 Reply With Quote
Old Mar 27, 2005, 03:41 PM   #4
ketema@ketema.n
Thread Starter
macrumors newbie
 
Join Date: Mar 2005
#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....
ketema@ketema.n is offline   0 Reply With Quote
Old Mar 27, 2005, 03:49 PM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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 is offline   0 Reply With Quote
Old Mar 27, 2005, 03:52 PM   #6
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
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!
robbieduncan is offline   0 Reply With Quote
Old Mar 27, 2005, 04:00 PM   #7
ketema@ketema.n
Thread Starter
macrumors newbie
 
Join Date: Mar 2005
Got it! That works fine. Thanks...to many windows though....
ketema@ketema.n is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
MBP Debug with osciloscope applereball MacBook Pro 0 Dec 4, 2013 08:01 AM
View NSArrays while Debug'n larswik iPhone/iPad Programming 2 Feb 17, 2013 01:33 AM
Debug console query nashyo iPhone/iPad Programming 1 Nov 19, 2012 09:42 AM
Calendar debug mode - how to ? maclab OS X 10.8 Mountain Lion 11 Sep 16, 2012 11:35 PM
Debug iOS from Terminal Garbag3man117 iPhone/iPad Programming 0 Jun 10, 2012 04:26 PM

Forum Jump

All times are GMT -5. The time now is 05:25 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC