#include <stdio.h> int main(){ char str[20]; fgets(str, 20, stdin); // read from stdin puts(str); // print read content out to stdout // open the file FILE *f = fopen("file.txt" , "r"); // if there was an error if(f == NULL){ perror("Error opening file"); // print error return(-1); } // if there was no error else{ fgets(str, 20, f); // read from file puts(str); // print read content out to stdout } fclose(f); // close file return(0); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter