Okay, so in this program I have to read a string of characters then write that into a file. The max characters it can be is 20. Anyway, the problem I have is that when I use scanf() you can't enter spaces in the name. So when I put in gets() it just skips the user input and goes to the next step, what have i done wrong? Here is the slice of code from my function:
product_id is a global variable that's why it isnt listed, so is offset. Yes I know its bad to do but our teacher made us do it. I don't think this is the problem though....
Code:
void update(FILE *fp) {
int qty;
float cost;
char name[21];
printf("Enter old product id:");
scanf("%d", &product_id);
if (search(fp, &offset)) {
printf("ERROR\n");
}
else {
fseek(fp, offset, SEEK_SET);
printf("Product id Found Successfully\n");
printf("\nEnter New Product Id That is Unique:");
scanf("%d", &product_id);
printf("Enter New Product Name(20 character max):");
gets ( name );
printf("Enter New Product Quantity:");
scanf("%d", &qty);
printf("Enter New Product Price:");
scanf("%f", &cost);
fprintf(fp, "%4d %20.20s %4d %10.2f", product_id, name, qty, cost);
} /* end else */