How to read content from a text file in C

1 Answer

0 votes
#include <stdio.h>
  
void readFile(char file[]) {
    FILE *fp = fopen(file, "r");
       
	char ch;
    while ((ch = fgetc(fp)) != EOF)
        putchar(ch);

    fclose(fp);
}
  
int main()
{
    char file[100] = "d:\\data.txt";
  
    readFile(file);
  
    return 0;
}
   
     
     
     
/*
run:
     
c c++ c#
java python 
  
*/
 
 

 



answered Jul 8, 2020 by avibootz
edited Jul 8, 2020 by avibootz

Related questions

2 answers 196 views
2 answers 194 views
1 answer 142 views
1 answer 140 views
1 answer 167 views
...