|
-
Jun 26th, 2002, 07:38 PM
#1
Thread Starter
Hyperactive Member
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 
-
Jun 28th, 2002, 01:50 PM
#2
You need to take the address of the character:
Code:
strcat(num[i], &sztext[i]);
Z.
-
Jun 28th, 2002, 01:59 PM
#3
Frenzied Member
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."
-
Jun 28th, 2002, 02:37 PM
#4
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++;
}
-
Jun 28th, 2002, 03:11 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|