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. ATL / WTL / STL
  4. argv does not equal string (char*)

argv does not equal string (char*)

Scheduled Pinned Locked Moved ATL / WTL / STL
comdata-structuresquestion
3 Posts 2 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.
  • X Offline
    X Offline
    XTAL256
    wrote on last edited by
    #1

    I am using the command line to pass values. The values are numbers or "ni" for negative infinity (& pi for positive). This is my code:

    if (argv[1] == "ni")
    // do something

    But it fails. It never evaluates to true :wtf:. Why is this? "ni" is a char array and so is argv[], is it just me or is something going on. I tried this on Windows and Unix and the same thing happened. Download here[^] for the full source

    M 1 Reply Last reply
    0
    • X XTAL256

      I am using the command line to pass values. The values are numbers or "ni" for negative infinity (& pi for positive). This is my code:

      if (argv[1] == "ni")
      // do something

      But it fails. It never evaluates to true :wtf:. Why is this? "ni" is a char array and so is argv[], is it just me or is something going on. I tried this on Windows and Unix and the same thing happened. Download here[^] for the full source

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      That's not how you compare C-style strings. Use strcmp() instead.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

      X 1 Reply Last reply
      0
      • M Michael Dunn

        That's not how you compare C-style strings. Use strcmp() instead.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

        X Offline
        X Offline
        XTAL256
        wrote on last edited by
        #3

        yes, i fixed the problem. I just converted to string. I forgot that C-strings are just pointers, so you are actually comparing the memory locations. However, i could have sworn i had seen it written before (unless it was to specifically compare memory locations)

        Customer in computer shop: "Can you copy the Internet onto this disk for me?"

        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