•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 391,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,752 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 193 | Replies: 6
![]() |
•
•
Join Date: Mar 2008
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 0
Hello
char **pOutData; /* Output results */
char *ptoken
I have a pointer which contains the following
hdjhasdjkhasd;stephenjohnson;647823463;dhasdjhaj
I want to work through and get out just stephenjohnson
I have the following so far, which does not work....any help?
char **pOutData; /* Output results */
char *ptoken
I have a pointer which contains the following
hdjhasdjkhasd;stephenjohnson;647823463;dhasdjhaj
I want to work through and get out just stephenjohnson
I have the following so far, which does not work....any help?
c Syntax (Toggle Plain Text)
for ( size = 0; size < b2b_data_drill_nNoSelect; size++ ) { if (size == 1 ) { ptoken = strtok(pOutData, ";" ); while( ptoken != NULL ) { printf ("Results 2nd:%s\n", pOutData[size] ); printf ("ptoken:%s\n", ptoken ); ptoken = strtok(NULL, ";" ); } } }
Last edited by Ancient Dragon : Apr 14th, 2008 at 9:41 am. Reason: add code tags
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,561
Reputation:
Rep Power: 36
Solved Threads: 860
pOutData appears to be a pointer to a pointer or a 2d array of strings, like argv parameter to main() In either event line 5 can not work because strtok() only works with 1d character arrays. pOutData needs to be a pointer that is declared similar to the way you declared pToken
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,561
Reputation:
Rep Power: 36
Solved Threads: 860
I would copy the string into some local buffer because strtok() will replace the ; with null characters, which destroys the original string.
char temp[255]; strcpy(temp,*pOutData); pToke = strtok(temp,","); // rest of program here
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Mar 2008
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 0
ah it is working, except at the end the program is bombing out
any ideas?
for ( size = 0; size < b2b_data_drill_nNoSelect; size++ )
{
if (size == 1 )
{
strcpy(temp,pOutData[size]);
//printf("Temp = %s\n", temp);
ptoken = strtok(temp, ";" );
while( ptoken != NULL )
{
printf ("Results 2nd:%s\n", pOutData[size] );
printf ("ptoken:%s\n", ptoken );
ptoken = strtok(NULL, ";" );
}
}
}
any ideas?
Last edited by sjgriffiths : Apr 14th, 2008 at 10:26 am.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,561
Reputation:
Rep Power: 36
Solved Threads: 860
>>except at the end the program is bombing out
Don't know -- probably something else in your program. Did you declare temp variable big enough to hold all the characters in that string ?
>>if (size == 1 )
Why that condition? Just delete the loop and do it like this, unless of course there is other code within that loop that you haven't posted.
Don't know -- probably something else in your program. Did you declare temp variable big enough to hold all the characters in that string ?
>>if (size == 1 )
Why that condition? Just delete the loop and do it like this, unless of course there is other code within that loop that you haven't posted.
strcpy(temp,pOutData[1]);
//printf("Temp = %s\n", temp);
ptoken = strtok(temp, ";" );
while( ptoken != NULL )
{
printf ("Results 2nd:%s\n", pOutData[1] );
printf ("ptoken:%s\n", ptoken );
ptoken = strtok(NULL, ";" );
}
Last edited by Ancient Dragon : Apr 14th, 2008 at 10:33 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Other Threads in the C Forum
- Previous Thread: Windows Programming (Win 32 API)
- Next Thread: fork and exit system calls



Linear Mode