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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
App crashes when Archived using Release but works fine with Debug... dbramhall iPhone/iPad Programming 5 Apr 17, 2012 07:49 PM
Using Mic Input With iOS Simulator Wellington2k iPhone/iPad Programming 0 Oct 16, 2011 01:12 PM
Eclipse Java EE Helio (sr 2) debug perspective not scrolling with breakpoint? robm99x Mac Programming 0 Mar 24, 2011 06:27 AM
How to input to my Java Tool in XCode 3 while Debugging Zali Mac Programming 0 Mar 28, 2008 05:59 PM


All times are GMT -5. The time now is 10:34 AM.

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

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