Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to correct this warning?

how to correct this warning?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mybm1
    wrote on last edited by
    #1

    Quote:

    warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’

    L _ 2 Replies Last reply
    0
    • M mybm1

      Quote:

      warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The message is telling you how to correct it; you must use a char* parameter for the %s format type. See http://msdn.microsoft.com/en-us/library/56e442dc.aspx[^].

      M 1 Reply Last reply
      0
      • L Lost User

        The message is telling you how to correct it; you must use a char* parameter for the %s format type. See http://msdn.microsoft.com/en-us/library/56e442dc.aspx[^].

        M Offline
        M Offline
        mybm1
        wrote on last edited by
        #3

        ok ,thnk u but for the parameter char ** what format we should declared to print?

        L 1 Reply Last reply
        0
        • M mybm1

          ok ,thnk u but for the parameter char ** what format we should declared to print?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Read the documentation I gave you the link for; it describes all the available format types and what parameters they require. There is no format type that handles char**, for a very good reason.

          1 Reply Last reply
          0
          • M mybm1

            Quote:

            warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            The format %s is used to output a null terminated string. The variable it expects is a char*. I can think of 2 possibilities. Since you haven't posted any relevant code, I'm only guessing here. First guess is that you're trying to print a string and are using an extra & character -

            char string[20];
            printf("%s", &string); // The & is not needed here.

            Second guess is that you've received a char** as a function argument and trying to print it.

            void fun(char** arg)
            {
            printf("%s", *arg); // * is needed here.
            }

            It would be best if you can post the relevant code.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++) (October 2009 - September 2013)

            Polymorphism in C

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups