YouTip LogoYouTip

C Examples Read File

# C Example - Read a Line from a File [![Image 1: C Examples](#) C Examples](#) Read a line from a file. Content of file tutorial.txt: $ cat tutorial.txt google.com ## Example #include#include // exit() function int main(){char c; FILE *fptr; if((fptr = fopen("tutorial.txt", "r")) == NULL){printf("Error! opening file"); // Exit if file pointer returns NULL exit(1); }// Read text until a new line is encountered fscanf(fptr,"%[^n]", c); printf("Read content:n%s", c); fclose(fptr); return 0; } Output: Read content: [![Image 2: C Examples](#) C Examples](#)
← Python3 Built In FunctionsC Examples Time Structure β†’