Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 9-Mar-13 20:13pm
Edited 9-Mar-13 22:12pm
(no name)14.3K
v2
Comments
Richard MacCutchan at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100