Luna/apps/edit.c
apio a18e50ff34
All checks were successful
continuous-integration/drone/push Build is passing
apps: Add cat and edit
2023-03-24 00:52:26 +01:00

36 lines
543 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
FILE* f;
if (argc < 2)
{
fprintf(stderr, "usage: %s [file]", argv[0]);
return 1;
}
f = fopen(argv[1], "w");
if (!f)
{
perror(argv[1]);
return 1;
}
char buffer[4096];
while (1)
{
char* rc = fgets(buffer, sizeof(buffer), stdin);
if (rc == 0) break;
if (!strcmp(rc, "EOF\n")) break;
fputs(buffer, f);
}
fclose(f);
return 0;
}