Thread: warning C4013...errrrrr!

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    How? :-(
    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 Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    Code:
    typedef struct
    {
    	enum diaSemana dia;
    	char hora;
    }Horario;
    Code:
    typedef struct medico
    {
    	char nome[200];
    	char morada[300];
    	int contacto;
    
    	char especialidade[100];
    	int numPacientes;
    	int idMedico;
    
    	Horario horarioTrab[5];
    
    }Medico;
    Medico listaMedico[10];

    I'm trying to save data into listaMedico
    "Artificial Intelligence usually beats natural stupidity."

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by IndioDoido View Post
    How? :-(
    Like you've done with Nome and Morada.
    Code:
    int main()
    {
    	char c;
    	fgets(c, sizeof(c), stdin); /* Bad! */
    	char array[100];
    	fgets(array, sizeof(array), stdin); /* Good! */
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    i resolved the char to char array warnings :-D thanks alot, but i still get warnings in the int:

    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
    "Artificial Intelligence usually beats natural stupidity."

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    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?
    "Artificial Intelligence usually beats natural stupidity."

  7. #22
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if gets() is bad, why do teachers reference it and not fgets()?
    Lack of knowledge?

    And why do compilers still use it?
    backward compatibility
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #23
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Probably because their textbook of choice is 20 years old.
    Mainframe assembler programmer by trade. C coder when I can.

  9. #24
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    Lol...ok :-D

    going to start using fgets() at all times.

    Tnx alot everyone for the help :-)
    "Artificial Intelligence usually beats natural stupidity."

  10. #25
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by IndioDoido View Post
    Now i get 16 warnings:
    Excellent. That means the header file is doing what it is supposed to -- revealing programming errors which would otherwise go unnoticed.

  11. #26
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    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:
    Name:
    Address: ...
    I tryed to use fflush(stdin) but no result :-(

    And every time i run the program and enter a int value it crashes :-(
    Last edited by IndioDoido; 03-20-2008 at 03:51 PM.
    "Artificial Intelligence usually beats natural stupidity."

  12. #27
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    You may want to spend some time in the FAQ.
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Never use fflush(stdin) and showing the code helps more than a thousand words.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM