Friday, January 8, 2010

C programming

Code to deep copy a string in C

char*  deepcopy(char* str1){
        char *copy  = malloc (strlen(str1));
        sprintf(copy, str1);
        return copy;
}




1. When I compile, I am getting the error: 'EOF' undeclared (first use in this function)

Solution: #include < stdio.h >

2. In visual studio output window just flashes and disappears. What can I do to make it stay.

Run the program using Ctrl F5 instead of just F5


3. When I compile a simple program I am getting the error "Cannot open include file: 'iostream.h': No such file or directory". How can I fix this.

Check if iostream is stored in C:\Program Files\Microsoft Visual Studio 8\VC\include folder. Sometimes it is stored just as iostream instead of iostream.h . If that is the case add #include < iostream> omitting .h

4.LINK : fatal error LNK1104: cannot open file 'C:\Documents and Settings/...............

Usual reason is that the same program is running and a terminal window is waiting for input.