What are you trying to read into? If you are not trying to read into a string, gets(), fgets(), etc, are all wrong approaches.Quote:
How? :-(
Printable View
What are you trying to read into? If you are not trying to read into a string, gets(), fgets(), etc, are all wrong approaches.Quote:
How? :-(
Code:typedef struct
{
enum diaSemana dia;
char hora;
}Horario;
Medico listaMedico[10];Code:typedef struct medico
{
char nome[200];
char morada[300];
int contacto;
char especialidade[100];
int numPacientes;
int idMedico;
Horario horarioTrab[5];
}Medico;
I'm trying to save data into listaMedico
i resolved the char to char array warnings :-D thanks alot, but i still get warnings in the int:
Quote:
warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
warning C4024: 'fgets' : different types for formal and actual parameter 1
warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
warning C4024: 'fgets' : different types for formal and actual parameter 1
Code:printf("\nContacto: ");
fgets(temp[n].contacto,sizeof(temp[n].contacto),stdin); //<--- int
printf("\nID de Medico: ");
fgets(temp[n].idMedico,sizeof(temp[n].idMedico),stdin); //<--- int
fgets wants a char*, a char array, not an int.
You can't read into an integer with fgets.
Since you are reading integer input, I would say the easiest way is scanf.
all done :-)
once again thanks...
by the way...
if gets() is bad, why do teachers reference it and not fgets()? And why do compilers still use it?
Lack of knowledge?Quote:
if gets() is bad, why do teachers reference it and not fgets()?
backward compatibilityQuote:
And why do compilers still use it?
Probably because their textbook of choice is 20 years old.
Lol...ok :-D
going to start using fgets() at all times.
Tnx alot everyone for the help :-)
ups!
i have another question...
i have to fill data like name, address, etc...and when i was running my prog to test it, i was going to insert the name field, but it "jumped" and showed the address field :-(
Example:
I tryed to use fflush(stdin) but no result :-(Quote:
Name:
Address: ...
And every time i run the program and enter a int value it crashes :-(
You may want to spend some time in the FAQ.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Never use fflush(stdin) and showing the code helps more than a thousand words.