Last active
July 1, 2024 16:42
-
-
Save vadimkantorov/ddc28e0d29360d436e44e26b01a96de2 to your computer and use it in GitHub Desktop.
Example cat program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc cat.c -o cat && ./cat cat.c | |
#include <stdio.h> | |
int main(int argc, char* argv[]) | |
{ | |
char buf[1024]; | |
if(argc < 2) return 2; | |
FILE* f = fopen(argv[1], "r"); | |
if(!f) return 1; | |
do | |
{ | |
size_t cnt = fread(buf, 1, sizeof(buf), f); | |
fwrite(buf, 1, cnt, stdout); | |
} | |
while(!feof(f) && !ferror(f)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment