Intermediate C Frequently Asked Questions (FAQ)

 

Q. Is there a news group to support C?
Q. When you allocate an array of pointers, then allocate each pointer in the array, does one free release it all?
Q.I can view the source code on-ilne, but when I try to download, I get HTML code. How can I get it?
Q. Why do I get an error about WinMain when I compile my program?
Q. Why do I get errors about REGS and/or int86 when I compile scrnio.c?
Q. What is the difference between a GUI and Console program?
 


Q. Is there a news group to support C?

A. The primary newsgroup where you can post questions is comp.lang.c. If you find the newsgroup helpful, you should also try to answer questions there, as it will also help you learn. Just make sure your answer isn't wrong, otherwise someone else will!


Q. When you allocate an array of pointers, then allocate each pointer in the array, does one free release it all?

A. No. The basic rule here is, you should have a free for each malloc you did. If you did 1 malloc for the array, and it had 4 elements, then you malloc'ed each elements, that 5 mallocs. You would need to do 5 free's to correctly clean up. Some other rules: Never use more than you allocated. Never use a block after it was free'd. Never free a block more than once.


Q.I can view the source code on-ilne, but when I try to download, I get HTML code. How can I get it?

A. When viewing the files, copy and paste their content into a notepad file. Then, copy and paste them from notepad into your source editor. Going to notepad first should eliminate any unusual HTML formatting codes.

 


Q. Why do I get an error about WinMain when I compile my program?

A. This means that your compiler is trying to create a Windows GUI program, not a console (or text-mode) program. If your using Borland C++, try right-clicking on the Project window, and selecting 'Target Expert' from the pop-up menu. Then, in Target Expert, make sure that 'Target Model' says Console, and not GUI.


Q. Why do I get errors about REGS and/or int86 when I compile scrnio.c?

A. This is a portability issue. Since these functions are non-ANSI standard, they are supposed to have an underscore in front, but not all compilers follow that rule. If you are having problems with REGS, try changing it to _REGS. If your having a problem with int86(), try changing it to _int86().


Q. What is the difference between a GUI and Console program?

A. Basically, their appearance and how they are written. A GUI program is a typical windows program, it has buttons, list-boxes, edit-boxes, and other graphical controls. A Console program is a text-mode program. From a programmers standpoint, a GUI program has a WinMain, while a console program has a main function (there are many many other differences). When Windows runs a Console program, it usually dos it in a 'DOS-Box', which looks like a window. Also, with a Console program, you can press ALT-ENTER to switch it ti full-screen mode, and back to again to normal size.

The Browser you are using to view this program is a GUI program. To see a console program, go to the Start Button, click it, then Run. Next to 'Open', type EDIT and click the OK button. This is a Console editor program. You can select the Console program's File, then Exit menu choices to exit it.