Ниже я написал программу, которая пытается прочитать и распечатать значения структуры. Я думал, что scanf игнорирует /n для всех типов данных, кроме char, но когда я запускаю приведенную ниже программу и предоставляю первый ввод как целое число. Я не получаю o/p для имени переменной. Почему??
#include <stdio.h>
#include <string.h>
struct employee
{
int empno;
char name[10];
float p_money;
};
int main()
{
struct employee e;
struct employee *ptr;
ptr = &e;
printf("please enter the empno \n");
scanf("%d", &(ptr->empno));
printf("please enter the name \n");
gets(ptr->name);
//scanf("%d", &(ptr->empno));
printf("please enter the money \n");
scanf("%f", &(ptr->p_money));
printf("Roll No: %d\n", ptr->empno);
printf("Name: %s\n", ptr->name);
printf("Money: %f\n", ptr->p_money);
getchar();
return 0;
}
Исполнение:
please enter the empno
10
please enter the name
please enter the money
100.99
Номер рулона: 10 Имя: Деньги: 100,989998
please enter the empno
10jackal
please enter the name
please enter the money
100.99
Свиток №: 10 Имя: шакал Деньги: 100,989998
fgets(). - person ThiefMaster   schedule 20.11.2013