Results 1 to 5 of 5

Thread: strings, pointers, messy..

  1. #1

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

    strings, pointers, messy..

    What im trying to do is read a string of numbers in a textbox and if its a digit concatanate them together until I come to a "," then repeat the process. for example.. 56,77,13,66,843 it would read 5(its a digit) then 6(its a digit) then it will hit "," and move ahead to repaet the process. heres what I have anyone know a good functions to use or a few suggestions, thanks alot

    Code:
    char sztext[200];
    
    retval = GetWindowText(gradebx,sztext,200);
    
    char num[200][5];
    int i;
    
    for(i=0;i<size;i++)
    {
    	if(isdigit(sztext[i]))
    	{
    		strcat(num[i],sztext[i]);
    	}
    }
    i get the error

    strcat' : cannot convert parameter 2 from 'char' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.
    Matt

  2. #2
    Zaei
    Guest
    You need to take the address of the character:
    Code:
    strcat(num[i], &sztext[i]);
    Z.

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well, not quite, cos sztext[ i ] will be one character in the middle of a string, and strcat is expecting a string, not a character. If you just give it the address, it will append the whole rest of the string until it hits a '\0' character.

    You could do it with strncat(). strncat() will only concatentate a given number of characters, so you can tell it to only concatenate 1:

    Code:
    strncat(num[i], sztext[i], 1);
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    jim mcnamara
    Guest
    Try:
    Code:
    char sztext[200];
    char *buf,*s;
    int i,j;
    char num[200][5];
    memset(num,0x00,sizeof(num)); // string functions require trailing nulls
    int retval = GetWindowText(gradebx,sztext,200);
    buf=sztext;
    j=0;
    s=num[j];
    // assuming sztext is null-terminated ....
    while(*buf!=0x00)
    {
    	if(isdigit(*buf) )*s++=*buf;
                        if(*s==',') {
                               j++;                    
                               s=num[j];
                        }
                        buf++;
    }

  5. #5
    Zaei
    Guest
    Erm, sorry for not reading the post correctly =). At least it got people's attention =).

    Z.

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