CS19001/CS19002 Programming and Data Structures Laboratory

Autumn/Spring semester

Frequently Asked Questions


My program works in my home PC, but not here.

You must be using a non-standard compiler in your home. The most likely culprit is the Turbo C compiler. You may, for example, get the following error message on a program compiled under Turbo C.
   myprog.c:1:19: conio.h: No such file or directory
The standard header file for ANSI C is <stdio.h>, not <conio.h>. Use Microsoft's Visual C++ compiler or the Windows gcc/gpp compiler. Download gcc compilers from here.


My program works in the lab, but not in the home.

Again the reason is most likely the use of a nonstandard compiler. Use VC++ or gcc.


I have included <math.h>, but am still getting the error:
/home/a53/tmp/ccgOZE1o.o(.text+0x30): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit status

Compile with the -lm flag:
   cc myprog.c -lm


I have defined the function myfunction, but still getting the error message:
/home/a53/tmp/ccE8gEBo.o(.text+0x45): In function `main':
: undefined reference to `myfuction'
collect2: ld returned 1 exit status

Well, you have defined myfunction, but not myfuction. The converse mistake, i.e., defining myfuction but calling myfunction, has a similar effect, but may be a bit more difficult to locate. Check for typos.


What is segmentation fault?

Segmentation faults are caused by unauthorized access of memory. For you, the most likely cause is that you forgot the ampersand (&) in your scanf statement.

If all your scanf's are okay and you are playing with arrays or dynamic memory, you need to bother about segmentation faults. Whenever you try to access (read or write) memory locations not allotted to you, this fault occurs. It is then necessary to debug your code and locate the exact place where this illegal memory access occurs. The process is not always easy. C programmers learn to live gracefully with segmentation faults. You too should!


My book says it is not always necessary to include <stdio.h>.

That is true. But it may be too difficult for you to determine when you program requires <stdio.h>. Many funny errors (compilation or run-time) may be caused by the fact that you did not include this header file. We advocate you to make it a habit to include <stdio.h> in any C program you write. Doing that brings you absolutely no harm, but saves many unwelcome hassles.


Should I give three > signs for the third output, four for the fourth, and so on?

Absolutely no! Please note that the single > sign means `rewrite a file', whereas the double >> sign stands for the `append' operator. Create the output file for the first run. For all subsequent runs, append to that file.


My printout does not display wide lines.

Our printers can print at most 80 characters per line. It is up to you to ensure that every line in your code and output fits in this width. Carefully check the printer file before firing the print command.


Course home