Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
FILE *fp1,*fp2;
char ch;
fp1=fopen("TEST.txt","w");
if(fp1==NULL)
{ 
            printf("FILE can't be opened for writing");
            exit(1);
            }
            printf("Enter characters to quit enter $");
            do
            {
                          ch=getchar();
                          if(ch!='$');
                          putc(ch,fp1);
                          }while(ch!='$');
                          
                          fclose(fp1);
                          
                          fp2=fopen("TEST.txt","r");
                          
                          if(fp2==NULL)
                          {
                                       printf("FIlE can't be opened for reading");
                                       exit(1);
                                       }
                                       
                                       int charcount=0;
            while(!feof(fp2))
            {
                            ch=getc(fp2);
                            printf("%c",ch);
                            charcount++;
                            }
                           
                            printf("\nCount of characters=%c\n",charcount);
                           
                            fclose(fp2);
                           
                            return 0;
            }


The error I am getting:
C:/TC/BIN/count_char_files.c:17: undefined reference to `_streams'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x73):C:/TC/BIN/count_char_files.c:17: undefined reference to `_streams'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x7b):C:/TC/BIN/count_char_files.c:17: undefined reference to `_streams'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x81):C:/TC/BIN/count_char_files.c:17: undefined reference to `_streams'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x90):C:/TC/BIN/count_char_files.c:17: undefined reference to `_streams'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x95):C:/TC/BIN/count_char_files.c:17: undefined reference to `_fgetc'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0xcf):C:/TC/BIN/count_char_files.c:19: undefined reference to `_fputc'
C:\DOCUME~1\Arijit\LOCALS~1\Temp/cccFbaaa.o(.text+0x154):C:/TC/BIN/count_char_files.c:31: undefined reference to `_fgetc'
collect2: ld returned 1 exit status

Execution terminated

What went wrong in my code?
Posted
Updated 9-Mar-13 21:12pm
v2
Comments
Richard MacCutchan 10-Mar-13 5:05am    
I don't know what compiler/builder you are using, but it looks like you are missing a file reference to the C runtime libraries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900