I want take input from user and then save that input into the file. In my below code if I remove my while loop then the file is appended but I want this loop so that user can enter data upto 500 characters.
int main()
{
char Buffer1[5];
FILE *ot;
fopen_s(&ot, "D:\\export1.txt", "a+");
fseek(ot, 0L, SEEK_END);
int sz = ftell(ot);
printf("Enter Data.\n");
while (sz<500) {
for (int i = 0; i < 5; i++) {
scanf_s("%c", &Buffer1[i]);
}
// write data to file
for (int i = 0; i < 5; i++) {
fputc(Buffer1[i], ot);
}
sz = ftell(ot);
}
fclose(ot);
_gettch();
return 0;
}