当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C语言程序设计》课程教学资源:TURBO C 2.0:ANSWERS TO COMMON QUESTIONS

资源类别:文库,文档格式:DOC,文档页数:12,文件大小:17.55KB,团购合买
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
点击下载完整版文档(DOC)

TURBO C 2.0: ANSWERS TO COMMON QUESTIONS Getting started 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 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 Users 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 users 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

TURBO C 2.0: 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 setting your options however you want to set them, and typing alt-O/S Integrate Environment 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. Q. Why do i get the message Linker Error: Unable to open input file COx. OB A. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories. This option is specified under the Options/Directories menu. The INSTall program initially sets th option to a directory where it copied the start-up and library files Q. How do i get Turbo c to link in my own libraries or use multiple A. Turbo C s Project facility is designed to allow you to work with multiple files. Refer to Chapter 3 of the turbo C User s Guide under Projects: Using Multiple Source Programs Q. Why does the linker tell me that all the graphics library routines are undefined? A. The Options/ Linker/ Graphics Library item must be set on, if you are using any Turbo c graphics functions and have not specifyed GRAPHICS LiB in a project file Q. Why does Turbo C report Unable to open include file stdarg. h

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. Q. Why do I get the message: Linker Error: Unable to open input file 'C0x.OBJ' A. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories. This option is specified under the Options/Directories menu. The INSTALL program initially sets this option to a directory where it copied the start-up and library files. Q. How do I get Turbo C to link in my own libraries or use multiple source files? A. Turbo C's Project facility is designed to allow you to work with multiple files. Refer to Chapter 3 of the Turbo C User's Guide, under "Projects: Using Multiple Source Programs". Q. Why does the linker tell me that all the graphics library routines are undefined? A. The Options/Linker/Graphics Library item must be set ON, if you are using any Turbo C graphics functions and have not specifyed GRAPHICS.LIB in a project file. Q. Why does Turbo C report "Unable to open include file 'stdarg.h

when I try to #include ? A. The most probable reason is that you have exceeded the number of files that dos can have open simultaneously. Add the line FILES= to your DOS CONFIG. sys file. This allows dos to open up to 20 files at the same time. CONFIG. sys will only be effective after you have rebooted your computer. See the IBM DOS Reference Manual for details on the config. sys file Q. How do i change the colors of the editor and menus in TC? A. The utility TCINst eXe allows you to customize your colors. Q. How do i get a listing of my source code to my printer? A. From within the turbo C editor hit k. This will print a marked block to the printer If no block is marked this key sequence will print the entire file in your editor Q. When I Make, Run, or Trace a program Turbo C sometimes goes through the compile and link process even when the object files A. Turbo C s mAKe logic works solely on a files date and time file marked with a date thats sometime in the future, the ob ject files that are reated from it will always be older than the source file and Turbo C will always try to rebuild the file. You can fix this by using TOUCH. Com to set the file to the current date and time. You should also make sure that your systems date and time are always properly set Comma nd -line compile r 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 by the -I switch. The INSTALL rogram initially writes a configuration file(TURBoC. CFG)that sets this to the directory where it copied all the turbo C * h files

when I try to #include ? A. The most probable reason is that you have exceeded the number of files that DOS can have open simultaneously. Add the line FILES=20 to your DOS CONFIG.SYS file. This allows DOS to open up to 20 files at the same time. CONFIG.SYS will only be effective after you have rebooted your computer. See the IBM DOS Reference Manual for details on the CONFIG.SYS file. Q. How do I change the colors of the editor and menus in TC? A. The utility TCINST.EXE allows you to customize your colors. Q. How do I get a listing of my source code to my printer? A. From within the Turbo C editor hit . This will print a marked block to the printer. If no block is marked this key sequence will print the entire file in your editor. Q. When I Make, Run, or Trace a program Turbo C sometimes goes through the compile and link process even when the object files are up-to-date. A. Turbo C's MAKE logic works solely on a file's date and time stamp. If one of your source files is marked with a date that's sometime in the future, the object files that are created from it will always be older than the source file, and Turbo C will always try to rebuild the file. You can fix this by using TOUCH.COM to set the file to the current date and time. You should also make sure that your system's date and time are always properly set. C o m m a n d - L i n e C o m p i l e r --------------------------------------------------------------------- - 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 by the -I switch. The INSTALL program initially writes a configuration file (TURBOC.CFG) that sets this to the directory where it copied all the Turbo C *.h files

Q. Why do i get the messag Linker Error: Unable to open input file COx. OBJ A. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories. This option is specified by the -L switch. If you allow tcc to invoke the linker it will search the directories in the configuration file (TURBoC. CFG) written by the INSTALL program. If you run tLINK, the configuration file is not read Q. Why does the linker tell me that all the graphics library routines are undefined? A. TCC will not search the graphics library unless you tell it to You should specify the graphics library on the command line. For example, to compi le bg idemo, type TCC BGIDEMO C GRAPHICS. LIB e r a I/0 Q. The '\n' in cprintfo does not return the cursor to the beginning of the line. It only moves the cursor down one line. A. cprintf( no longer interprets,\n' as a Carriage Return/ Line Feed combination. The\n only outputs a Line Feed. To force the cursor to the beginning of the line, manually insert a Carriage Return cprintf (\n\r) Q. How do i print to the printer from a turbo c program? A. Turbo C uses a File pointer (stdprn) defined in the STDIO. H file. You do not need to open stdprn before using it #include main( fprintf(stdprn,"Hello, world\n") Note that if your printer is line-buffered, the output i

Q. Why do I get the message: Linker Error: Unable to open input file 'C0x.OBJ' A. The linker searches for Turbo C start-up and library files in the Turbo C Library Directories. This option is specified by the -L switch. If you allow TCC to invoke the linker, it will search the directories in the configuration file (TURBOC.CFG) written by the INSTALL program. If you run TLINK, the configuration file is not read. Q. Why does the linker tell me that all the graphics library routines are undefined? A. TCC will not search the graphics library unless you tell it to. You should specify the graphics library on the command line. For example, to compile BGIDEMO, type TCC BGIDEMO.C GRAPHICS.LIB G e n e r a l I / O --------------------------------------------------------------------- - Q. The '\n' in cprintf() does not return the cursor to the beginning of the line. It only moves the cursor down one line. A. cprintf() no longer interprets '\n' as a Carriage Return/ Line Feed combination. The '\n' only outputs a Line Feed. To force the cursor to the beginning of the line, manually insert a Carriage Return: cprintf("\n\r"); Q. How do I print to the printer from a Turbo C program? A. Turbo C uses a FILE pointer (stdprn) defined in the STDIO.H file. You do not need to open stdprn before using it: #include main() { fprintf(stdprn, "Hello, world\n"); } Note that if your printer is line-buffered, the output is

flushed only after a\n is sent. Q. I am reading and writing binary files. My program is translating the Carriage Return(OxOD) and Line Feed(OxOA) characters. How do I prevent this from happening? A. Files opened in text mode will translate these characters for DOS. To read a file in binary mode, open it in binary mode Fo r examp #inc lude main o FILE binary fp char buffer [100] binary fp fopen("MYFILE. BIN",rb") fread(buffer, sizeof (char), 100, binary fp) The default file mode is text Q. Why don't printf and puts print text in color? A. Use the console I/0 functions cprintfo and cputso for color output #include maino textcolor (BlUe) cprintf("im blue. Q. How do i print a long integer? A. Use the ld format long int I =70000L: printf(%ld", 1)

flushed only after a '\n' is sent. Q. I am reading and writing binary files. My program is translating the Carriage Return (0x0D) and Line Feed (0x0A) characters. How do I prevent this from happening? A. Files opened in text mode will translate these characters for DOS. To read a file in binary mode, open it in binary mode. For example #include main() { FILE *binary_fp; char buffer[100]; binary_fp = fopen("MYFILE.BIN", "rb"); fread(buffer, sizeof(char), 100, binary_fp); : } The default file mode is text. Q. Why don't printf() and puts() print text in color? A. Use the console I/O functions cprintf() and cputs() for color output. #include main() { textcolor(BLUE); cprintf("I'm blue."); } Q. How do I print a long integer? A. Use the "%ld" format: long int l = 70000L; printf("%ld", l);

Q. How do i print a long double? A. Use the %Lf format long double ldbl lE500 printf(%Lf", ldb1 ex ample progra ms Q. How do I compile the MICroCALc spread sheet? A. See Appendix G of the Turbo C Reference Manua Q. How do I compile the BGIDEMo program? A. 1. Make sure that the following Turbo C files are in your current directory BGIDEMO. C 3. Load BGIDEMo c into the Editor by hitting F3 then typir BGIDEMO 3. go to the run menu and choose the run item Q. How do I create a Com file? A. DOs versions 3. 2 and earlier include an eXe2bin utility that converts exe files to com files. For users who do not have EXE2BIN, the Turbo C command-line linker, TLINK will create a COM file instead of an eXE file if the /t option is specified. For example tcc -mt -lt tiny will create TiNy. CoM instead of TINY. eXe There are certain limitations in converting an eXe file to a COM file. These limitations are documented in the IBM Disk Operating System manual under eXe2Bin

Q. How do I print a long double? A. Use the "%Lf" format. long double ldbl = 1E500; printf("%Lf", ldbl); E x a m p l e P r o g r a m s --------------------------------------------------------------------- - Q. How do I compile the MICROCALC spread sheet? A. See Appendix G of the Turbo C Reference Manual. Q. How do I compile the BGIDEMO program? A. 1. Make sure that the following Turbo C files are in your current directory: BGIDEMO.C *.BGI *.CHR 2. Run TC. 3. Load BGIDEMO.C into the Editor by hitting F3 then typing BGIDEMO 3. Go to the Run menu and choose the Run item. Q. How do I create a COM file? A. DOS versions 3.2 and earlier include an EXE2BIN utility that converts EXE files to COM files. For users who do not have EXE2BIN, the Turbo C command-line linker, TLINK will create a COM file instead of an EXE file if the /t option is specified. For example: tcc -mt -lt tiny will create TINY.COM instead of TINY.EXE. There are certain limitations in converting an EXE file to a COM file. These limitations are documented in the IBM Disk Operating System manual under EXE2BIN

Turbo C s TINY model is compatible with the CoM format, but programs that use Turbo C s floating point routines cannot be converted to a CoM fi Gr a phi c Q. Why do i get the error message GI Error: graphics not initialized (use 'initgraph') when I use a graphics function? My program has already called initgraph o A. For some reason initgraph( failed. To find out why, check the return value of graphresulto. For #include int gerr; /*k graphics error * int driver DETECT, gmode /* Initialize graphics using auto-detection and look for the. BGI and. ChR files in the C: \ TURBoC directory. initgraph (&driver, &gmode, C: \\TURBOC if ((gerr graphresulto) printf( error: %s\n", grapherrormsg(gerr)) Ma th/ floating point Q. Why do i get incorrect results from all the math library functions like coso and tan(?

Turbo C's TINY model is compatible with the COM format, but programs that use Turbo C's floating point routines cannot be converted to a COM file. G r a p h i c s --------------------------------------------------------------------- - Q. 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(). A. For some reason initgraph() failed. To find out why, check the return value of graphresult(). For example: #include main() { int gerr; /* graphics error */ int gdriver = DETECT, gmode; /* Initialize graphics using auto-detection and look for the .BGI and .CHR files in the C:\TURBOC directory. */ initgraph(&gdriver, &gmode, "C:\\TURBOC"); if ((gerr = graphresult()) != grOk) { printf("Error : %s\n", grapherrormsg(gerr)); exit(1); } : } M a t h / F l o a t i n g P o i n t --------------------------------------------------------------------- - Q. Why do I get incorrect results from all the math library functions like cos() and tan()?

A. You must #include before you call any of the standard Turbo C math functions. In general, Turbo C assumes that a function that is not declared returns an int. In the case of math functions they usually return a double. For example /* WRONG * /-* RIGHT * #include maino printf(%f", cos(0)) printf(%f", cos(0)) Q. How do i trap a floating point error? A. See the signalo and matherr o functions in the Turbo C Reference Guide. The signalo function may be used to trap errors in the 80x87 or the 80x87 emulator. The matherr o function traps errors in the Math library functions L i nkererrors Q. Why do i get the message Linker Error: Unable to open input file COx. OBJ A. See Integrated Environment section above Q. Why do i get the message Linker Error: Undefined symbol main in module cO A. Every C program must contain a function called main (.This is the first function executed in your program. The function name must be all in lower case. If your program does not have one, create one. If you are using multiple source files the file that contains the function maino must be one of the files listed in the Project Note that an underscore character is prepended to al external turbo C symbol Q. Why does the linker tell me that all the graphics library routines are undefined A. See the "Integrated Environment and Command-line Compiler

A. You must #include before you call any of the standard Turbo C math functions. In general, Turbo C assumes that a function that is not declared returns an int. In the case of math functions, they usually return a double. For example /* WRONG */ /* RIGHT */ #include main() main() { { printf("%f", cos(0)); printf("%f", cos(0)); } } Q. How do I "trap" a floating point error? A. See the signal() and matherr() functions in the Turbo C Reference Guide. The signal() function may be used to trap errors in the 80x87 or the 80x87 emulator. The matherr() function traps errors in the Math Library functions. L i n k e r E r r o r s --------------------------------------------------------------------- - Q. Why do I get the message: Linker Error: Unable to open input file 'C0x.OBJ' A. See "Integrated Environment" section above. Q. Why do I get the message: Linker Error: Undefined symbol '_main' in module C0 A. Every C program must contain a function called main(). This is the first function executed in your program. The function name must be all in lower case. If your program does not have one, create one. If you are using multiple source files, the file that contains the function main() must be one of the files listed in the Project. Note that an underscore character '_' is prepended to all external Turbo C symbols. Q. Why does the linker tell me that all the graphics library routines are undefined? A. See the "Integrated Environment" and "Command-line Compiler

sections above Q. What is a Fixup overflow? A. See the listing of TLINK error messages in Appendix d of the Turbo C Reference Guide Q. I am linking my own assembly language functions with turbo C. he linker reports that all of my functions are undefined. A. Make sure that you have put an underbar character in front of 11 assembly language function names to be called by Turbo C. Your assembly language program should be assembled with Case Sensitivity. See the Chapter 12, Advanced programming, in the Turbo C Users Guide for detail other Questions Q. How do i change the stack size? A. The size of the stack of a Turbo c program is determined at run-time by the global variable stklen. To change the size to. fe ple 10000 bytes, include the following line in your pro extern unsigned stolen =10000 This statement must not be inside any function definition. The default stack size is 4096 bytes(4K) Q. I m getting a Stack Overflow! message when I run my program. How can i work around this? A. You may increase the stack size by following the procedure above overflows are usually caused by a large amount of local data or recursive functions. You can decrease the amount of stack space used by declaring your local variables static maino main char x[5000] static char x[5000

sections above. Q. What is a 'Fixup overflow'? A. See the listing of TLINK error messages in Appendix D of the Turbo C Reference Guide. Q. I am linking my own assembly language functions with Turbo C. The linker reports that all of my functions are undefined. A. Make sure that you have put an underbar character '_' in front of all assembly language function names to be called by Turbo C. Your assembly language program should be assembled with Case Sensitivity. See the Chapter 12, "Advanced Programming," in the Turbo C User's Guide for details. O t h e r Q u e s t i o n s --------------------------------------------------------------------- - Q. How do I change the stack size? A. The size of the stack of a Turbo C program is determined at run-time by the global variable _stklen. To change the size to, for example 10000 bytes, include the following line in your program: extern unsigned _stklen = 10000; This statement must not be inside any function definition. The default stack size is 4096 bytes (4K). Q. I'm getting a 'Stack Overflow!' message when I run my program. How can I work around this? A. You may increase the stack size by following the procedure above. Stack overflows are usually caused by a large amount of local data or recursive functions. You can decrease the amount of stack space used by declaring your local variables static: main() main() { { char x[5000]; --> static char x[5000];

f course, you should be that there are other effects that the static keyword as applied here Q. My program comes up with the message Null pointer assignment after it terminates. What does this mean? A. Before a small-data model turbo C program returns to dos, it will check to see if the beginning of its data segment has been corrupted This message is to warn you that you have used uninitialized pointers or th t your program has corrupted memory in some other way. Q. Why are. EXE files generated by TC. eXe larger than those generated by TCC. EXE? A. In the default configuration, TC. eXe includes debugging nformation in the. exe files that it creates, and TCC. exe does not. If you don t want to produce this debugging information, you can shut it off in the Integrated Development Environment by selecting Alt-D/S/N. Q. Why do i get declaration syntax error messages on DOS. H? A. You have set the Ansi keywords only option oN. Keep this option OFF when using any keywords specific to Turbo C Q. I have a working program that dynamically allocates memory using malloch or calloc in small data models (tiny, smal and medium). When I compile this program in large data models (compact, large, and huge) my program hangs. A. Make sure that you have #include in your program. Q. I am linking my own assembly language functions with Turbo C But the linker reports that all of my functions are undefined A. See answer above in the Linker section Q. My far pointers wrap around when they are incremented over 64K. How do i reference a data ob ject that is ter

: : } } Of course, you should be aware that there are other effects that the "static" keyword has, as applied here. Q. My program comes up with the message 'Null pointer assignment' after it terminates. What does this mean? A. Before a small-data model Turbo C program returns to DOS, it will check to see if the beginning of its data segment has been corrupted. This message is to warn you that you have used uninitialized pointers or th t your program has corrupted memory in some other way. Q. Why are .EXE files generated by TC.EXE larger than those generated by TCC.EXE? A. In the default configuration, TC.EXE includes debugging information in the .EXE files that it creates, and TCC.EXE does not. If you don't want to produce this debugging information, you can shut it off in the Integrated Development Environment by selecting Alt-D/S/N. Q. Why do I get "declaration syntax error" messages on DOS.H? A. You have set the "Ansi keywords only" option ON. Keep this option OFF when using any keywords specific to Turbo C . Q. I have a working program that dynamically allocates memory using malloc() or calloc() in small data models (tiny, small, and medium). When I compile this program in large data models (compact, large, and huge) my program hangs. A. Make sure that you have #include in your program. Q. I am linking my own assembly language functions with Turbo C. But the linker reports that all of my functions are undefined. A. See answer above in the "Linker" section. Q. My far pointers "wrap around" when they are incremented over 64K. How do I reference a data object that is greater than 64K? A. Use huge pointers

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共12页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有