Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Confused about stricmp
QtWS25 Last Chance

Confused about stricmp

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 4 Posters 4.2k Views
  • 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
    Monkey666
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      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
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          Monkey666
          wrote on last edited by
          #4

          Thanks that worked, now to test :)

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AlterX
              wrote on last edited by
              #6

              [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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved