Question about (lstrcmpi)

This is a discussion on Question about (lstrcmpi) within the Windows Programming forums, part of the Platform Specific Boards category; I have this: Code: hExtra=CreateFile("Path.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ReadFile(hExtra, Buffer, 100, &dwBytes2, NULL); DeleteFile(Buffer); But it did ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question Question about (lstrcmpi)

    I have this:

    Code:
     
    hExtra=CreateFile("Path.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    ReadFile(hExtra, Buffer, 100, &dwBytes2, NULL);
     
    DeleteFile(Buffer);
    But it did not work, then I tried this:

    Code:
     
    TCHAR Buffer[100];
     
    hExtra=CreateFile("Path.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    ReadFile(hExtra, Buffer, 100, &dwBytes2, NULL);
     
    DeleteFile(Buffer);
    But that didn't help either.
    Ken Fitlike helped me on a question very simalar to this before and it used the lstrcmpi function. So I assume this problem would use it too. But I don't know how I should use it. Any help? Thanks in advance.

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    This doesn't help either:

    Code:
     lstrcmpi(Buffer,_T(Buffer));

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Drop the _T macro - like any other macro it does a literal text substitution; you should only use it on pure text, never a variable name.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    If you want to delete a file who's name is stored in Path.txt then you don't need lstrcmpi to do that since lstrcmpi is used to compare to strings.
    I have a feeling your problem is caused by the string being read in from the file not being NULL terminated since .txt files don't usually contain zero bytes.
    You could loop thru the buffer and change all '\r' and '\n' charactors to zeros that would mean you end a line with a zero.
    Code:
    int Index=0;
    
    hExtra=CreateFile("Path.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    ReadFile(hExtra, Buffer, 100, &dwBytes2, NULL);
    while(Index<99)
       {
          if (Buffer[Index]=='\r' || Buffer[Index]=='\n')
             break;
          Index++;
       }
       Buffer[Index]=0;
    DeleteFile(Buffer);
    In this example the program loops untill it finds a '\r' or '\n' charactor or it reaches the end of the buffer and adds a zero.
    If the file is going to cotain more then one line then you should create a function to either get a single line from the file at a time or split the input up into lines.
    Last edited by Quantum1024; 05-04-2005 at 04:56 PM.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks, Quantum1024

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21