kmitl-profund-exercise/pipetofile/main.cpp

24 lines
579 B
C++
Raw Normal View History

2023-04-02 18:14:10 +00:00
#include<stdio.h>
#include<stdlib.h>
int main() {
FILE * fp;
char input[100]={0},cha;
printf("Input data here under this line\n");
printf("-------------------------------\n");
int i=0;
fp=fopen("/tmp/data.txt","w+");
while(input[0]!='.'){
while((cha=getchar())!='\n'&&cha!=EOF){
input[i]=cha;
i++;
}
input[i]='\0';
i=0;
fprintf(fp,"%s\n", input);
}
fclose(fp);
printf("Output has been saved to /tmp/data.txt\nYou can safely close this window now.");
return 0;
}