I am trying to relearn C by going through the K&R exercises (I have the first, non-ANSI, edition...that's how long it's been since I last programmed in C under Unix as a software engineer).

I have Visual C++.net version 2003 on a Windos XP computer. I would prefer to continue using this compiler because it is used where I work and I want to learn C++ next. The problem that I am having is trying to figure out how to get the IDE to co-exist with the K&R exercises. It was easy when I was using Unix because C and Unix were designed to work together. I could write a program using printf, scanf, getchar, putchar, stdin, sdtout, stderr, etc. and then compile under Unix and have all the Unix redirections, pipes, etc. at my disposal. With the IDE under Windows its not clear how to compile and run programs that use the ANSI standard file I/O routines. I assume that you use the Run command but I haven't figured out how to get out of the IDE and the documentation from microsoft isn't helping. Any help that you could provide would be greatly appreciated. Thank you.

Frank

Recommended Answers

All 5 Replies

Create your program as a Command Line program, or whatever your compiler calls it.
Build it creating an executable.
Open a command prompt window Start:Accessories:Command Prompt.
Navigate to the directory -- sorry, folder -- the executable is created in.
Enter the name of the executable.
IOW -- You edit and build the program in the IDE, switch to the prompt to run the program.

Or you can run the program from the IDE and a command line window will open. But you have to stop the program just before it exits because the window closes immediately. getchar() is probably all you need. I usually don't recommend this technique because of the added code to keep the window open.

Third option is check the documentation and see if you can run the compiler from the command line. Use an editor to create the source, use the command line to compile and run the program. Personally, my preferred option.

It would be better IMO to actually learn ANSI-C.
K&R C is strictly historical or for old code requiring long term maintenance.

I agree with Salem -- buy a new book. You wouldn't teach your son or daughter to drive with horse & buggy so why learn to program with that ancient and long-out-of-date book.

Thanks for your prompt suggestions. I am definitely going to buy the ANSI-C version of the K&R book. But I expect to have the same problem of trying to run the exercises under the IDE instead of Unix. I saw in another post from Narue that you can tell the compiler to compile C code rather than C++ code. That would be a good start. Thanks again for your help.

Frank

>>can tell the compiler to compile C code rather than C++ code.
Yes, just name the source file with *.c extension instead of *.cpp and the IDE will know how to compile it.

>>I am definitely going to buy the ANSI-C version of the K&R book
Get a different book because even that one is out-of-date. See the Read Me threads at the top of this and the c++ boards for good suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.