Menu

Implicit declaration of function

2008-07-22
2012-09-26
  • vipers falcon

    vipers falcon - 2008-07-22

    sprintf(SendFocusScreenMessage(),"%s \"%s\" aged %i was transfered to our ship",Crew.GetCrewMiscIdByName(Crew.GetLastEnteredCrewName()),Crew.GetLastEnteredCrewName(),Crew.GetCrewAgeByName(Crew.GetLastEnteredCrewName()));

    When Itry to compile this line whit Dev-C++, the compiler gives me this error

    " implicit declaration of function `int sprintf(...)' "

    What do I have to correct

     
    • Wayne Keen

      Wayne Keen - 2008-07-22

      Well, your Basic 3 would be a much better place to start than a single line of code and an error message...

      Wayne

       
    • vipers falcon

      vipers falcon - 2008-07-22

      int ReturnCode=Crew.ProcessUniversalMMu();
      switch(ReturnCode)
      {
      case UMMU_TRANSFERED_TO_OUR_SHIP:
      sprintf(SendFocusScreenMessage(),"%s \"%s\" aged %i was transfered to our ship",Crew.GetCrewMiscIdByName(Crew.GetLastEnteredCrewName()),Crew.GetLastEnteredCrewName(),Crew.GetCrewAgeByName(Crew.GetLastEnteredCrewName()));
      break;
      case UMMU_RETURNED_TO_OUR_SHIP:
      sprintf(SendFocusScreenMessage(),"%s \"%s\" aged %i entered into our ship",Crew.GetCrewMiscIdByName(Crew.GetLastEnteredCrewName()),Crew.GetLastEnteredCrewName(),Crew.GetCrewAgeByName(Crew.GetLastEnteredCrewName()));
      break;
      }

       
      • Wayne Keen

        Wayne Keen - 2008-07-22

        The "Basic 3" are covered in the thread titled "Please Read Before Posting a Question".

        Wayne

         
        • Wayne Keen

          Wayne Keen - 2008-07-22

          Note that the error message about an implicit definition means that the compiler doesn't know what that function is. In this case, with a function like sprintf, this may mean that you have not included the appropriate header that tells the compiler what the function is.

          This means that posting single lines of code, or even entire functions will probably not be sufficient to figure things out. This is why having a stand-alone piece of example code is a much better way to get help.

          Is this code you have written, or are you just trying to compile code someone else has given you?

          Wayne

           
    • vipers falcon

      vipers falcon - 2008-07-23

      I have add "#include <stdio.h>"

      But when I try to compile the project there are no errors, but in the compiler and linker output there are more line like this.

      C:\Docum........................... undefined reference to...................

      and at the end there is

      c:.................undefined reference to `WinMain@16'

       
      • Wayne Keen

        Wayne Keen - 2008-07-23

        Basic 3?

        Read the thread titled "PLEASE READ BEFORE POSTING A QUESTION"?

        Wayne

         
        • Wayne Keen

          Wayne Keen - 2008-07-23

          Please stop excerpting errors - you are throwing away vital information - which is why I keep asking for your "Basic 3".

          I see two things from what you posted:

          (1) It looks like you are storing your project in a path with spaces in it,probably "My Documents" - this is a very bad idea.

          (2) The error message about not finding WinMain is actually discussed in the FAQ - you probably either do not have a main function in a console application, or lack a WinMain if you are compiling a windows application.

          Jumping to a conclusion here - it looks like someone gave you source code for a game or something, and you are trying to compile it without a lot of knowledge about coding - you just want to play the game, right?

          Wayne

           
    • cpns

      cpns - 2008-07-22

      sprintf() is explicitly declared in <stdio.h> / <cstdio>

      In C++ it is illegal to have an implicit declaration, in C it is valid and the compiler will only generate a warning, but even in C it is not a good idea.

      Clifford

       
      • Wayne Keen

        Wayne Keen - 2008-07-22

        Do you perceive a mismatch between the code and question Clifford?

        Wayne

         
        • cpns

          cpns - 2008-07-22

          You mean sophisticated code, novice question?

          New code maintainer perhaps?

          Any how, I hope this code is for your Navy and not mine! ;)

          Clifford

           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.