can i know is there any restriction while using string in loop?? as far as i know, my reference book don't say anything about the behaviour of string when using it within the loop. but when i code it, when to put the input, i mean the string, it don't behave like the integer. let say a program ask for the name and a salary. for i=0, we enter the first name and then the salary. then increment i++, but when i=1, the program straightly jump to the salary and not asking about the name. why is it happened?? any restriction? i did us fgets, gets, scanf but nothing make difference and show the progress that i wanted for.
Code:
#include <stdio.h>
#include <string.h>
main()
{
FILE *fp;
int i;
char name[20];
float salary;
fp=fopen("Detail.txt","w");
if(fp==NULL)
{
printf("\nThe file cannot be opened");
close(1);
}
for(i=0; i<2; i++)
{
puts("\nEnter your name : ");
gets(name);
puts("\nEnter your salary : ");
scanf("%f", &salary);
fprintf(fp,"(%d) NAME : %s \nSALARY : %f \n ", i, name, salary);
}
fclose(fp);
}
[\code]