Luna/apps/edit.c

35 lines
502 B
C
Raw Normal View History

2023-03-23 23:52:26 +00:00
#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;
fputs(buffer, f);
}
fclose(f);
return 0;
}