I am making a grocery list program and I want to include a user-input string that is put it in the next available line in the text file. Right now this adds the string to the file, but it then puts in random characters for a number of spaces and then, if I input something else, it won't be on the next line.
void AddToFile(FILE *a) {
char addItem[20];
printf("Enter item: ");
scanf("%s", &addItem);
fwrite(addItem, sizeof(addItem), 1, a);
}