Hi! again!
Code:
add()
{
int x;
ptr=fopen("data.txt","a+");
for(x=0;x<2;x++)
{
printf("\nID: ");
scanf("%d",&field[x].id);
printf("\nName: ");
//Here's the code changed..
fgets(field[x].name, 25,stdin );
fflush(stdin);
// scanf(" %[^\n]",field[x].name);
printf("\nQty: ") ;
scanf("%d",&field[x].qty);
printf("\nPrice: ") ;
scanf(" %lf",&field[x].price);
fprintf(ptr, "%d|", field[x].id);
fprintf(ptr, "%s|", field[x].name);
fprintf(ptr, "%d|", field[x].qty);
fprintf(ptr, "%.2lf\n", field[x].price);
}
fclose(ptr);
return 0;
}
I just changed my code for the Name Input.. i want it to only accept 25 chars only.
the prob is when it stored into text file :
ex:
1|mickey
mouse|12|25.00
2|donald
duck|21|23.10