29 lines
606 B
C
29 lines
606 B
C
#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;
|
|
} |