Today I wrote a code at the university on VS 2013
and it worked. I sent it to myself through email to try at home. Its not working on VS 2017
. Fortunately I have VS 2013
and it does work on it. Why is this happening?
Here is the part of the code that fails on VS 2017
:
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct{
char name[50];
char pos[50];
double sel[12];
double annpay;
}sluj;
typedef struct{
int num;
sluj per[100];
}firma;
firma f;
int main(){
int i, j;
do{
printf("Enter number of employees\n");
scanf("%d", &f.num);
} while (f.num < 1 || f.num > 100);
for (i = 0; i < f.num; i++){
printf("Enter the name of employee:\n");
fflush(stdin);
fgets(f.per[i].name, 50, stdin); //it acts like this row doesnt exist
//and prints the text below
printf("Enter the position of employee:\n");
fgets(f.per[i].pos, 50, stdin); //basiclly the same thing as above, but on different
//structure member (both are defined char)
//and it works here!
for (j = 0; j < 12; j++){
printf("Enter salary for %d month\n", j+1);
scanf("%lf", &f.per[i].sel[j]);
}
}
for (i = 0; i < f.num; i++){
f.per[i].annpay = 0;
for (j = 0; j < 12; j++){
f.per[i].annpay += f.per[i].sel[j];
}
}
for (i = 0; i < f.num; i++){
if (f.per[i].annpay > 6000){
printf("\n%s %lf", f.per[i].name, f.per[i].annpay);
}
}
return 0;
}
I don't think the problem is with fflush
, because it doesn't work even without it.