[Dev-C++] What's up with scanf and struct's
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <jor...@wa...> - 2000-11-25 08:00:25
|
I'm a newbie. Does any body know what's wrong in the next simple =
program. It's my first time i define an struct, and the problem seems to =
be in the scanf instruction , because if i redefine "int num" to "char =
num[2]" and use gets() everything goes ok.
#include <stdio.h>
#include <conio.h>
#define MaxEnt 5
struct agenda
{
char nombre[25];
char direcc[25];
int num;
char tlf[9];
} listin[MaxEnt];
main()
{
int i, n=3D2;
for(i=3D0;i<MaxEnt;i++)
{
printf("Introduzca Nombre:");
gets(listin[i].nombre);
printf("Introduzca direccion:");
gets(listin[i].direcc);
printf("Introduzca numero:");
scanf("%i",&listin[i].num);
printf("Introduzca telefono:");
gets(listin[i].tlf);
}
for(i=3D0;i<n;i++)
printf("%s %s %s =
%s",listin[i].nombre,listin[i].direcc,listin[i].num,listin[i].tlf);
}
|