init
This commit is contained in:
29
writefile.c
Normal file
29
writefile.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define _FILE "test/text2.txt"
|
||||
|
||||
int main() {
|
||||
FILE *fp = fopen(_FILE, "w");
|
||||
|
||||
if (fp == NULL) {
|
||||
char *buf = malloc(256);
|
||||
sprintf(buf, "Error opening file `%s`", _FILE);
|
||||
perror(buf);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
char input[256];
|
||||
printf("Enter text...\n");
|
||||
do {
|
||||
scanf("%s", input);
|
||||
printf("Length of input: %ld\n", strlen(input));
|
||||
fprintf(fp, "%s\n", input);
|
||||
fflush(fp);
|
||||
} while (strlen(input) > 0 && input[0] != '.');
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user