well guys and gals, my problem is this, im pretty new to programming but i was pretty confident that this code would work, because the individual parts worked separately just fine... everything was going great, then when it got to the line with append(ap) it started the while loop all over.
Code:
#include <stdio.h>
void append(char an);
int main(){
int choice1;
int choice2;
char ap;
printf("_________________________________________________________________________________________________\n\n\n\n");
printf("Would you like to check inventory or update inventory?");
while(1){
printf("\n\n[1] check\n[2] update\n");
scanf("%d", &choice1);
switch (choice1){
case 1:
printf("\n this part hasn't been made yet");
break;
case 2:
printf("\nWould you like to add a new item or change an existing item?");
printf("\n\n[1] add\n[2] change\n");
scanf("%d", &choice2);
switch (choice2){
case 1:
printf("\nEnter the item you would like to add.");
ap=getchar();/*it breaks here, goes back to original switch(choice1), and then carries out append(ap for whatever you type even though it's no longer on this part of the program, any ideas?)*/
append(ap);
break;
case 2:
printf("\nnot yet made");
break;
default:
printf("\ninvalid entry, please re-enter:");
break;
}
break;
default:
printf("\ninvalid entry, please re-enter:");
break;
}
}
return 0;
}
void append(char an){
FILE *f;
f=fopen("temp.txt", "a");
fprintf(f, "%c", an);
fclose(f);
}
anyway i tried for a really long time to figure it out, but to no avail. so if anyone out there know what i did wrong, your help would be greatly appreciated. thankyou!