Results 1 to 2 of 2

Thread: arrays & strings

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Angry

    THe result of this is nothing
    Im not good at handling strings in array's but from the reference i've looked at this should work. I suspect the problem is in the last parameter of sendmessage, but have tried many combination and nothings worked!!

    Code:
     num = SendMessage(hwndlist, LB_GETCOUNT, 0, 0);
    char buffer[num];
                          for(i=0;i<num; i++){
                                         SendMessage(hwndlist,LB_GETTEXT, i,(LPARAM)buffer[i]);
                                         MessageBox (NULL, buffer , "message", 0);
                                         fputs(buffer, fp);
                                         fprintf(fp, "\n");
                                         }
    Thanks for your help.
    Matt

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    char only holds a single character, not a string. You'd need something similar to:
    Code:
    num = SendMessage(hwndlist, LB_GETCOUNT, 0, 0);
    char *buffer[num];
    
    for(i = 0; i < num; i++) {
        long lLen = SendMessage(hwndlist, LB_GETTEXTLEN, i, 0);
        buffer[i] = new char[lLen+1]; // Include space for terminator
        SendMessage(hwndlist, LB_GETTEXT, i, (LPARAM)buffer[i]);
        MessageBox (NULL, buffer[i], "message", 0);
        fprintf(fp, "%s\n", buffer[i]);
    }
    
    for(i = 0; i < num; i++) {
        delete[] buffer[i];
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width