CS Electrical And Electronics
@cselectricalandelectronics

gets statement is getting skipped in C programming? How to fix this?

All QuestionsCategory: C Languagegets statement is getting skipped in C programming? How to fix this?
chetan shidling asked 3 years ago

Here is the code.
 
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;
char name[20];
int age, n, i, salary;
// clrscr();
// Opening file for writing
fptr = fopen(“C:\\Users\\HP\\Desktop\\ds\\file.txt”, “w”);
if(fptr == NULL)
{
printf(“File does not exists \n”);
return;
}
printf(“Number of Users you want to enter : “);
scanf(“%d”, & n);
for(i=1;i<=n;i++)
{
printf(“Person Details\n”);
printf(“Enter the name\n”);
gets(name);
fprintf(fptr, “Name = %s\n”, name);
printf(“Enter the age\n”);
scanf(“%d”, &age);
fprintf(fptr,”Age = %d\n”, age);
printf(“Enter the salary \n”);
scanf(“%d”, & salary);
fprintf(fptr,”Salary = %d\n”, salary);
printf(“\n”);
}
fclose(fptr);
getch();
return 0;
}
 
The output I am getting is:
 
Number of Users you want to enter : 3
Person Details
Enter the name
Enter the age
21
Enter the salary
32333