TURBO C 2.01: ANSWERS TO COMMON QUESTIONS G e t t i n g S t a r t e d ---------------------------------------------------------------------Q. How do I install Turbo C? A.

Run the INSTALL program from the INSTALL/HELP disk. To start the installation, change your current drive to the one that has the install program on it and type INSTALL. You will be given instructions in a box at the bottom of the screen for each prompt. For example, if you will be installing from drive A:, type: A: INSTALL At this point, the INSTALL program will appear with menus selections and descriptions to guide you through the installation process. Q. How do I run Turbo C? A. After you have installed Turbo C, type "TC" from the DOS prompt and you're ready to go. Chapter 2 (Getting Started) of the Turbo C User's Guide will guide you through your first Turbo C program. Q. What is the difference between TC.EXE and TCC.EXE? A. The Turbo C package comes with two compilers, an Integrated Environment named TC.EXE and a command-line compiler named TCC.EXE. The Integrated Environment is essentially the command-line compiler with an integrated editor, linker, and debugger. Please refer to the Turbo C User's Guide for details on using both systems. Q. What is a configuration file? A. A configuration file tells Turbo C what options to default to and where to look for its library and header files. TC.EXE looks for a configuration file named TCCONFIG.TC, and TCC.EXE looks for a file named TURBOC.CFG. See the User's Guide, pages 40 and 143 for more information. Q. How do I create a configuration file? A. When you run the INSTALL program it creates a configuration file named TURBOC.CFG for TCC.EXE. This file is just an ASCII file which you can change with any text editor. It contains the path information for the library and header files for TCC.EXE to use. The INSTALL program does not create a TCCONFIG.TC file for TC.EXE because it installs the directory information directly into TC.EXE. You can create a configuration file for TC.EXE by running TC, setting your options however you want to set them, and typing Alt-O/S. I n t e g r a t e d E n v i r o n m e n t ---------------------------------------------------------------------Q. Why is Turbo C not able to find any of my #include files? A. The compiler searches for include files in the Turbo C Include Directories. This option is specified under the Options/Directories menu. The INSTALL program initially sets this option to the directory where it copied all the Turbo C *.h files.

If one of your source files is marked with a date that's sometime in the future. Why do I get the message: Linker Error: Unable to open input file 'C0x. Q. Turbo C's MAKE logic works solely on a file's date and time stamp. You should also make sure that your system's date and time are always properly set. and Turbo C will always try to rebuild the file. This allows DOS to open up to 20 files at the same time. Q. or Trace a program Turbo C sometimes goes through the compile and link process even when the object files are up-to-date.OBJ' A. the object files that are created from it will always be older than the source file. How do I get Turbo C to link in my own libraries or use multiple source files? A. Why does the linker tell me that all the graphics library routines are undefined? A. The INSTALL program initially sets this option to a directory where it copied the start-up and library files. You can fix this by using TOUCH.LIB in a project file. Q.Q.h'" when I try to #include <stdio. A. When I Make. Add the line FILES=20 to your DOS CONFIG. . Q. Refer to Chapter 3 of the Turbo C User's Guide. The utility TCINST. if you are using any Turbo C graphics functions and have not specifyed GRAPHICS. From within the Turbo C editor hit <Ctrl><K><P>. The Options/Linker/Graphics Library item must be set ON.EXE allows you to customize your colors. CONFIG. How do I get a listing of my source code to my printer? A. Turbo C's Project facility is designed to allow you to work with multiple files. Run.h>? A. See the IBM DOS Reference Manual for details on the CONFIG.SYS will only be effective after you have rebooted your computer. How do I change the colors of the editor and menus in TC? A. This option is specified under the Options/Directories menu. Why does Turbo C report "Unable to open include file 'stdarg.COM to set the file to the current date and time. Q. If no block is marked this key sequence will print the entire file in your editor.SYS file. The most probable reason is that you have exceeded the number of files that DOS can have open simultaneously. Q. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories. under "Projects: Using Multiple Source Programs". This will print a marked block to the printer.SYS file.

open it in binary mode. For example. Turbo C uses a FILE pointer (stdprn) defined in the STDIO. I am reading and writing binary files. The INSTALL program initially writes a configuration file (TURBOC. the output is flushed only after a '\n' is sent. You do not need to open stdprn before using it: #include <stdio. A. This option is specified by the -L switch. it will search the directories in the configuration file (TURBOC. Why is Turbo C not able to find any of my #include files? A. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories.C GRAPHICS.H file. Q.L i n e C o m p i l e r ---------------------------------------------------------------------Q. You should specify the graphics library on the command line. Why does the linker tell me that all the graphics library routines are undefined? A. Files opened in text mode will translate these characters for DOS.LIB<Enter> G e n e r a l I / O ---------------------------------------------------------------------Q. Q. type TCC BGIDEMO. Why do I get the message: Linker Error: Unable to open input file 'C0x. to compile BGIDEMO.CFG) written by the INSTALL program. How do I prevent this from happening? A. manually insert a Carriage Return: cprintf("\n\r"). If you allow TCC to invoke the linker.h files. For example .OBJ' A. If you run TLINK. My program is translating the Carriage Return (0x0D) and Line Feed (0x0A) characters.C o m m a n d . } Note that if your printer is line-buffered. To force the cursor to the beginning of the line.h> main() { fprintf(stdprn. It only moves the cursor down one line. cprintf() no longer interprets '\n' as a Carriage Return/ Line Feed combination. Q. the configuration file is not read.CFG) that sets this to the directory where it copied all the Turbo C *. The compiler searches for include files in the Turbo C Include Directories. Q. How do I print to the printer from a Turbo C program? A. To read a file in binary mode. world\n"). "Hello. The '\n' in cprintf() does not return the cursor to the beginning of the line. TCC will not search the graphics library unless you tell it to. The '\n' only outputs a Line Feed. This option is specified by the -I switch.

Load BGIDEMO. 3. Use the "%Lf" format. How do I print a long double? A. Make sure that the following Turbo C files are in your current directory: BGIDEMO. Q. sizeof(char). Use the "%ld" format: long int l = 70000L. binary_fp = fopen("MYFILE. ldbl).h> main() { textcolor(BLUE). } Q.#include <stdio. : } The default file mode is text. "rb"). Why don't printf() and puts() print text in color? A. binary_fp). #include <conio."). cprintf("I'm blue. fread(buffer.BIN". 100. char buffer[100].BGI *. E x a m p l e P r o g r a m s ---------------------------------------------------------------------Q. How do I print a long integer? A. 1. Q. long double ldbl = 1E500.h> main() { FILE *binary_fp. How do I compile the MICROCALC spread sheet? A. Run TC. l). Q.C into the Editor by hitting F3 then typing BGIDEMO<Enter> . printf("%ld".C *.CHR 2. Use the console I/O functions cprintf() and cputs() for color output. How do I compile the BGIDEMO program? A. See Appendix G of the Turbo C Reference Manual. printf("%Lf".

/* Initialize graphics using auto-detection and look for the . For some reason initgraph() failed.EXE. Turbo C's TINY model is compatible with the COM format.CHR files in the C:\TURBOC directory. For example: tcc -mt -lt tiny will create TINY. Go to the Run menu and choose the Run item.COM instead of TINY. To find out why. Why do I get the error message: BGI Error: graphics not initialized (use 'initgraph') when I use a graphics function? My program has already called initgraph(). but programs that use Turbo C's floating point routines cannot be converted to a COM file. These limitations are documented in the IBM Disk Operating System manual under EXE2BIN. check the return value of graphresult(). How do I create a COM file? A. if ((gerr = graphresult()) != grOk) { printf("Error : %s\n". gmode. DOS versions 3. exit(1). For users who do not have EXE2BIN. /* graphics error */ int gdriver = DETECT. &gmode.BGI and . There are certain limitations in converting an EXE file to a COM file. } : } M a t h / F l o a t i n g P o i n t ---------------------------------------------------------------------Q. For example: #include <graphics.2 and earlier include an EXE2BIN utility that converts EXE files to COM files. G r a p h i c s ---------------------------------------------------------------------Q.h> main() { int gerr. TLINK will create a COM file instead of an EXE file if the /t option is specified. the Turbo C command-line linker. grapherrormsg(gerr)). */ initgraph(&gdriver.3. Why do I get incorrect results from all the math library functions like cos() and tan()? . Q. A. "C:\\TURBOC").

Make sure that you have put an underbar character '_' in front of all assembly language function names to be called by Turbo C. See the listing of TLINK error messages in Appendix D of the Turbo C Reference Guide. Every C program must contain a function called main(). You must #include <math. the file that contains the function main() must be one of the files listed in the Project." in the Turbo C User's Guide for details. The matherr() function traps errors in the Math Library functions. The signal() function may be used to trap errors in the 80x87 or the 80x87 emulator. I am linking my own assembly language functions with Turbo C. A. Why do I get the message: Linker Error: Undefined symbol '_main' in module C0 A. How do I "trap" a floating point error? A. } Q.A. In the case of math functions. See the "Integrated Environment" and "Command-line Compiler" sections above. Q. Why does the linker tell me that all the graphics library routines are undefined? A. If you are using multiple source files. Note that an underscore character '_' is prepended to all external Turbo C symbols.h> before you call any of the standard Turbo C math functions. The function name must be all in lower case. Why do I get the message: Linker Error: Unable to open input file 'C0x.h> main() { printf("%f". See the Chapter 12. See "Integrated Environment" section above. cos(0)). This is the first function executed in your program. The linker reports that all of my functions are undefined. cos(0)). } /* RIGHT */ #include <math. Q. For example /* WRONG */ main() { printf("%f". In general. . create one. See the signal() and matherr() functions in the Turbo C Reference Guide. they usually return a double. Q. If your program does not have one. Your assembly language program should be assembled with Case Sensitivity. Q. Turbo C assumes that a function that is not declared returns an int.OBJ' A. What is a 'Fixup overflow'? A. "Advanced Programming. L i n k e r E r r o r s ---------------------------------------------------------------------Q.

In the default configuration. Why do I get "declaration syntax error" messages on DOS. small. How can I work around this? A.EXE does not.h> in your program. What does this mean? A. This message is to warn you that you have used uninitialized pointers or that your program has corrupted memory in some other way.H? A. and medium). See answer above in the "Linker" section. Why are .EXE files that it creates. . : } --> Of course. TC. This statement must not be inside any function definition. I am linking my own assembly language functions with Turbo C.EXE larger than those generated by TCC. The size of the stack of a Turbo C program is determined at run-time by the global variable _stklen. it will check to see if the beginning of its data segment has been corrupted. A. Q. Q. The default stack size is 4096 bytes (4K). for example 10000 bytes. Before a small-data model Turbo C program returns to DOS. How do I change the stack size? A. you can shut it off in the Integrated Development Environment by selecting Alt-D/S/N. and TCC. Q. You can decrease the amount of stack space used by declaring your local variables static: main() { char x[5000]. You have set the "Ansi keywords only" option ON. Q.EXE? A. you should be aware that there are other effects that the "static" keyword has. Q. I have a working program that dynamically allocates memory using malloc() or calloc() in small data models (tiny. Make sure that you have #include <alloc. as applied here. Stack overflows are usually caused by a large amount of local data or recursive functions. But the linker reports that all of my functions are undefined. To change the size to. and huge) my program hangs.O t h e r Q u e s t i o n s ---------------------------------------------------------------------Q. If you don't want to produce this debugging information. large.EXE files generated by TC. You may increase the stack size by following the procedure above. My program comes up with the message 'Null pointer assignment' after it terminates. I'm getting a 'Stack Overflow!' message when I run my program. Q. Keep this option OFF when using any keywords specific to Turbo C . When I compile this program in large data models (compact. include the following line in your program: extern unsigned _stklen = 10000. A. : } main() { static char x[5000].EXE includes debugging information in the .

How do I reference a data object that is greater than 64K? A. 1024). If. If you are having trouble. Q. An example of this is: #include <alloc. Q. How do I interface Turbo C routines to a Turbo Pascal program? A. Use huge pointers. for example you wanted a two-dimensional array of characters that was 1024 by 128. These files are packed in the file EXAMPLES. But since the size of this array is greater than 64K.h> char (huge *array)[128]. Q. My far pointers "wrap around" when they are incremented over 64K.Q. the declaration you would expect to write would be: char array[1024][128]. In the Huge model. refer to the User's Guide. How do I declare an array that's greater than 64K? A. : main() { : array = farcalloc(sizeof(*array).C on disk.ARC and you will need to UNPACK them before using them. the maximum is 64K per source module. The use of the "huge" keyword is necessary in the declaration of "array" since only a huge pointer can address objects greater than 64k. it must be allocated off the heap. contact Nantucket Technical Support. Arrays greater than 64K must be allocated off the heap. You may have a total of up to 64K global and static data in the Tiny. For example: i = array[30][56]. Small. : } The array can be accessed with the same code as an array not allocated off the heap. Can I declare more than 64K of global variables? A. Q. See the example programs CPASDEMO.PAS and CPASDEMO. will assign "i" the value stored at the 31st by 57th element in "array". . Compact and Large memory models. Medium. How do I get Clipper to link with Turbo C? A. For further discussion of huge pointers.