Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Last active July 1, 2024 16:42
Show Gist options
  • Save vadimkantorov/ddc28e0d29360d436e44e26b01a96de2 to your computer and use it in GitHub Desktop.
Save vadimkantorov/ddc28e0d29360d436e44e26b01a96de2 to your computer and use it in GitHub Desktop.
Example cat program
// 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