First off, I'm new at this Mac stuff. Got my first ever Mac yesterday, and I've been trying to get it all to work.
I'm studying Software Engineering at University, and the current (first) language we're working with will be C going to C++. I've installed xCode, which I've got working, however I would like to use TextMate for the actual writing as the snippets just makes it awesome.
I have a problem though, when I compile a simple code like this:
int main(void){ printf("Hello World\n"); return 0; }
it works fine, I get the compiled output from gcc (I believe it's GCC in xCode), however if I run this:
int main(void){ int number; printf("Give number: "); scanf("%d", &number); printf("Number provided was %d", number); }
What happens is I get the said console output window, however it does not allow me to actually input stuff, it merely slaps 0 in the scanf.
I used 5 hours last night trying to get everything to work, and I may have been searching on the wrong things, but I'm new at all this so please beare with me, and if there's a specific answer somewhere (thread here, stackoverflow etc) then a link would be awesome.
Hope someone can help me, as TextMate is just....awesome.
Best Regards Dennis
On 8 Sep 2011, at 11:48, Tquila wrote:
[…] if I run this:
int main(void){ int number; printf("Give number: "); scanf("%d", &number); printf("Number provided was %d", number); }
What happens is I get the said console output window, however it does not allow me to actually input stuff, it merely slaps 0 in the scanf.
Something like scanf reads from stdin. This only works (for interactive prompting) when running the program in a tty/pty (i.e. Terminal).
At one point we faked it by injecting code into everything being run from TextMate that would override open/read and prompt for reads on stdin. This caused (unfixable) problems starting with Snow Leopard when launching Preview and similar from TextMate (which is done e.g. when building LaTeX documents), so we removed the feature, but to get it back see this blog post: http://blog.macromates.com/2009/interactive-input/
We have a to-do about creating a pty environment for command executions, but this is a little down the list.