Luna/apps/edit.cpp
apio 724dab636c
All checks were successful
continuous-integration/drone/push Build is passing
apps: Switch to C++
2023-03-29 17:56:56 +02:00

35 lines
502 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;
fputs(buffer, f);
}
fclose(f);
return 0;
}