So I decided to try to do what I at least think you meant, if I'm not totally mistaken.
1. So I created a temporary buffer (I hope) and then checks for as long as the input
from the user is not -1. Add the characters to the users buffer (not sure if this step is correct though).
I am aware that I'm still overwriting the buffer.
This worked fine with only printing one sentence, of course, I never overwrite the buffer
then.
2. So I am trying to read in to file. That was not what I thought I were doing.
How do you mean I can use user->buffer to the file?
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 1000
#define TRUE 1
#define FALSE 0
#define AMT_USERS 1
typedef struct User {
char buffer[SIZE];
FILE* file;
}User;
void input(User *user);
void printToFile(User *user);
int main() {
User user[AMT_USERS];
input(user);
return 0;
}
void input(User *user) {
char buffer[SIZE];
int finished = FALSE;
while (finished == FALSE) {
fgets(buffer, SIZE, stdin);
if (strcmp(buffer, "-1\n") == 0) {
finished = TRUE;
}
if (strcmp(buffer, "-1\n") != 0) {
int i;
for (i = 0; i < SIZE; i++) {
user->buffer[i] = buffer[i];
}
}
}
printToFile(user);
}
void printToFile(User *user) {
user->file = fopen("text.txt", "w");
if (user->file == NULL) {
perror("Error");
}
//while (fgets(user->buffer, SIZE, user->file) != NULL) {
fprintf(user->file, "%s", user->buffer);
//}
fclose(user->file);
}