49 lines
680 B
C
49 lines
680 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
FILE *f;
|
||
|
if (argc < 2)
|
||
|
{
|
||
|
printf("usage : %s <arg> <filename> \n", argv[0]);
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
if (argc > 1)
|
||
|
{
|
||
|
if (strcmp(argv[1],"-a")==0)
|
||
|
{
|
||
|
f=fopen(argv[2],"a");
|
||
|
FILE *l;
|
||
|
char output[100];
|
||
|
while(!feof(l))
|
||
|
{
|
||
|
fputs(output,l);
|
||
|
fgets
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
f=fopen(argv[2],"w");
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
f=fopen(argv[1],"w");
|
||
|
}
|
||
|
|
||
|
|
||
|
char input[100]={" "};
|
||
|
|
||
|
fgets(input, 100, stdin);
|
||
|
while(strcmp(input,"quit\n")!=0)
|
||
|
{
|
||
|
fputs(input,f);
|
||
|
fgets(input, 100, stdin);
|
||
|
}
|
||
|
|
||
|
fclose(f);
|
||
|
return 0;
|
||
|
}
|