Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Confused about stricmp

    C++ Gurus
    4
    6
    3640
    Loading More Posts
    • 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
      Monkey666 last edited by

      There have been many threads ont he internet which have used the following and apparently is supposed to work for finding a process by name:

      @
      if (stricmp(proc.szExeFile, "test") == 0)
      @

      However that doesn't work for me, it gives an error about using WCHAR* where it should be CHAR*.

      So I tried using this function which I found:

      @
      void strcpy_wc(char *Dest, wchar_t *Src)
      {
      while (*Src)
      {
      *Dest++ = *Src++;
      }
      *Dest = 0;
      }
      @

      For this:

      @
      char *procName;
      strcpy_wc(procName, proc.szExeFile);
      if (stricmp(procName, "test") == 0)
      @

      But the app crashes, and when debugging I get segment fault error on line 5 of the function strcpy_wc()

      Any ideas?

      1 Reply Last reply Reply Quote 0
      • C
        cincirin last edited by

        If you work with unicode strings, I suggest you to use unicode version of the function that you mentioned above: wcscmp, wcscpy. However, you can transform your ansi C string in unicode format with "MultiByteToWideChar":http://msdn.microsoft.com/en-us/library/bb202786.aspx or "mbstowcs":http://msdn.microsoft.com/en-us/library/k1f9b8cy(v=vs.80).aspx

        1 Reply Last reply Reply Quote 0
        • L
          loladiro last edited by

          You can use wcscmp() instead of stricmp. Also, may I suggest using QProcess, if at all possible in your app.

          @
          if (wcscmp(proc.szExeFile, L"test") == 0)
          @

          1 Reply Last reply Reply Quote 0
          • M
            Monkey666 last edited by

            Thanks that worked, now to test :)

            1 Reply Last reply Reply Quote 0
            • L
              loladiro last edited by

              Just as a side note to explain the SIGSEV. You didn't allocate any memory for your Dest char*.

              1 Reply Last reply Reply Quote 0
              • A
                AlterX last edited by

                [quote author="Monkey666" date="1312207879"]There have been many threads ont he internet which have used the following and apparently is supposed to work for finding a process by name:

                @
                if (stricmp(proc.szExeFile, "test") == 0)
                @

                However that doesn't work for me, it gives an error about using WCHAR* where it should be CHAR*.

                [/quote]

                I've already used win32 API (i suppose you too). To solve the problem in Visual studio just set "Character set" within project setting to non unicode and you don't have anymore that problem

                Qt Ambassador
                Real-time cooperative teams: http://www.softairrealfight.net
                Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                https://codereview.qt-project.org/...

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post