Thread: warning C4013...errrrrr!

  1. #1
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194

    warning C4013...errrrrr!

    hi!

    warning C4013: 'printf' undefined; assuming extern returning int
    warning C4013: 'gets' undefined; assuming extern returning int
    i'm getting tierd of seeing these warnings, can anyone help me?

    here's the code where the warnings link to...
    Code:
    #include "medico.h"
    #include "estruturas.h"
    
    Medico inserirMedico()
    {
    	Medico temp;
    
    	int i;
    	
    	printf("\nNome: "); //<-- warning C4013
    	gets(temp.nome); //<-- warning C4013
    
    	printf("\nMorada: "); //<-- warning C4013
    	gets(temp.morada); //<-- warning C4013
    
    	printf("\nContacto: "); //<-- warning C4013
    	gets(temp.contacto); //<-- warning C4013
    
    	printf("\nEspecialidade: "); //<-- warning C4013
    	gets(temp.especialidade); //<-- warning C4013
    
    	printf("\nID de Medico: "); //<-- warning C4013
    	gets(temp.idMedico); //<-- warning C4013
    
    	temp.numPacientes = 0;
    
    	return temp;
    }
    "Artificial Intelligence usually beats natural stupidity."

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    #include <stdio.h>
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    hi todd...

    Now i get 16 warnings:
    warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    warning C4024: 'gets' : different types for formal and actual parameter 1
    Code:
    for(i=0; i<5; i++)
    	{
    		if(i==0)
    		{
    			printf("\nHorario para Segunda-Feira: ");
    			gets(temp.horarioTrab[i].hora); //<------
    			temp.horarioTrab[i].dia = 2;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Terca-Feira: ");
    			gets(temp.horarioTrab[i].hora); //<------
    			temp.horarioTrab[i].dia = 3;
    		}
    		if(i==2)
    		{
    			printf("\nHorario para Quarta-Feira: ");
    			gets(temp.horarioTrab[i].hora); //<------
    			temp.horarioTrab[i].dia = 4;
    		}
    		if(i==3)
    		{
    			printf("\nHorario para Quinta-Feira: ");
    			gets(temp.horarioTrab[i].hora); //<------
    			temp.horarioTrab[i].dia = 5;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Sexta-Feira: ");
    			gets(temp.horarioTrab[i].hora); //<------
    			temp.horarioTrab[i].dia = 6;
    		}
    	}
    "Artificial Intelligence usually beats natural stupidity."

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    This
    Code:
    gets(temp.horarioTrab[i].hora);
    requires a char array. Is it?
    Mainframe assembler programmer by trade. C coder when I can.

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

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    By the way, please note that gets() is bad.
    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

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Obviously not. Now you need to fix it.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Only now can the compiler begin to tell you all your errors. Not including an include file you need, hides the intentions of your program, from your compiler.

    Get line numbers for your program before you post it, and include the line numbers you receive in the warnings or errors. That way we don't waste time.

  9. #9
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    fix what? :-(
    "Artificial Intelligence usually beats natural stupidity."

  10. #10
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    gets() requires a char array, not a char.
    Mainframe assembler programmer by trade. C coder when I can.

  11. #11
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    medico.c(21) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
    medico.c(21) : warning C4024: 'gets' : different types for formal and actual parameter 1
    medico.c(27) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
    medico.c(27) : warning C4024: 'gets' : different types for formal and actual parameter 1
    medico.c(36) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    medico.c(36) : warning C4024: 'scanf' : different types for formal and actual parameter 1
    medico.c(42) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    medico.c(42) : warning C4024: 'scanf' : different types for formal and actual parameter 1
    medico.c(48) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    medico.c(48) : warning C4024: 'scanf' : different types for formal and actual parameter 1
    medico.c(54) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    medico.c(54) : warning C4024: 'scanf' : different types for formal and actual parameter 1
    medico.c(60) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char'
    medico.c(60) : warning C4024: 'scanf' : different types for formal and actual parameter 1
    medico.c
    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #define _CRT_SECURE_NO_DEPRECATE
    
    #include "medico.h"
    #include "estruturas.h"
    #include <stdio.h>
    
    Medico inserirMedico()
    {
    	Medico temp; //variável temporária
    
    	int i;
    	
    	printf("\nNome: ");
    	gets(temp.nome);
    
    	printf("\nMorada: ");
    	gets(temp.morada);
    
    	printf("\nContacto: ");
    	gets(temp.contacto);
    
    	printf("\nEspecialidade: ");
    	gets(temp.especialidade);
    
    	printf("\nID de Medico: ");
    	gets(temp.idMedico);
    
    	printf("\nHorario Semanal (1-Manha | 2-Tarde | 3-Dia Todo)\n");
    
    	for(i=0; i<5; i++)
    	{
    		if(i==0)
    		{
    			printf("\nHorario para Segunda-Feira: ");
    			scanf(temp.horarioTrab[i].hora);
    			temp.horarioTrab[i].dia = 2;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Terca-Feira: ");
    			scanf(temp.horarioTrab[i].hora);
    			temp.horarioTrab[i].dia = 3;
    		}
    		if(i==2)
    		{
    			printf("\nHorario para Quarta-Feira: ");
    			scanf(temp.horarioTrab[i].hora);
    			temp.horarioTrab[i].dia = 4;
    		}
    		if(i==3)
    		{
    			printf("\nHorario para Quinta-Feira: ");
    			scanf(temp.horarioTrab[i].hora);
    			temp.horarioTrab[i].dia = 5;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Sexta-Feira: ");
    			scanf(temp.horarioTrab[i].hora);
    			temp.horarioTrab[i].dia = 6;
    		}
    	}
    
    	temp.numPacientes = 0;
    
    	return temp;
    }
    "Artificial Intelligence usually beats natural stupidity."

  12. #12
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    gets() requires a char array, not a char
    i'm new in this, what must i do to resolve that warning?
    "Artificial Intelligence usually beats natural stupidity."

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm aghast at the stupidity of C compilers... This shouldn't compile. At all. The code is so wrong it will instantly crash the program.
    With that note in mind, here's what you should note: All functions require a header.
    You must include it. Always. Documentation says what header.
    Now. You must understand the difference between char* and char. When a function wants char*, it means a string array.
    Basically a lot of chars.
    Nome and morda are char arrays, which is what you must pass.
    Your scanf calls are also incorrect, since scanf takes two arguments.
    And replace gets with fgets. Typically fgets(buffer, sizeof(buffer), stdin) is equalient of gets(buffer).

    Gets is very, very bad and should never have been added or invented. Don't even think of it. Ever.
    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.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i'm new in this, what must i do to resolve that warning?
    Pass a string (char array) instead of a char as the argument. But again, do not use gets(). Use something like fgets() instead.
    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

  15. #15
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    how about now:
    Code:
    Medico inserirMedico()
    {
    	Medico temp; //vari&#225;vel tempor&#225;ria
    
    	int i;
    	
    	printf("\nNome: ");
    	fgets(temp.nome,sizeof temp.nome,stdin);
    
    	printf("\nMorada: ");
    	fgets(temp.morada,sizeof temp.nome,stdin);
    
    	printf("\nContacto: ");
    	fgets(temp.contacto,sizeof temp.contacto,stdin);
    
    	printf("\nEspecialidade: ");
    	fgets(temp.especialidade,sizeof temp.especialidade,stdin);
    
    	printf("\nID de Medico: ");
    	fgets(temp.idMedico,sizeof temp.idMedico,stdin);
    
    	printf("\nHorario Semanal (1-Manha | 2-Tarde | 3-Dia Todo)\n");
    
    	for(i=0; i<5; i++)
    	{
    		if(i==0)
    		{
    			printf("\nHorario para Segunda-Feira: ");
    			fgets(temp.horarioTrab[i].hora,sizeof temp.horarioTrab[i].hora,stdin);
    			temp.horarioTrab[i].dia = 2;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Terca-Feira: ");
    			fgets(temp.horarioTrab[i].hora,sizeof temp.horarioTrab[i].hora,stdin);
    			temp.horarioTrab[i].dia = 3;
    		}
    		if(i==2)
    		{
    			printf("\nHorario para Quarta-Feira: ");
    			fgets(temp.horarioTrab[i].hora,sizeof temp.horarioTrab[i].hora,stdin);
    			temp.horarioTrab[i].dia = 4;
    		}
    		if(i==3)
    		{
    			printf("\nHorario para Quinta-Feira: ");
    			fgets(temp.horarioTrab[i].hora,sizeof temp.horarioTrab[i].hora,stdin);
    			temp.horarioTrab[i].dia = 5;
    		}
    		if(i==1)
    		{
    			printf("\nHorario para Sexta-Feira: ");
    			fgets(temp.horarioTrab[i].hora,sizeof temp.horarioTrab[i].hora,stdin);
    			temp.horarioTrab[i].dia = 6;
    		}
    	}
    
    	temp.numPacientes = 0;
    
    	return temp;
    }
    Pass a string (char array) instead of a char as the argument.
    How? :-(
    "Artificial Intelligence usually beats natural stupidity."

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