|
-
Jan 17th, 2006, 08:46 PM
#1
Thread Starter
Frenzied Member
splitting a string up
is there a split function in c++?
e.g
_fstrcpy(data, split(data,1) );
or something, im not sure,
so if the var is
char Word[50] = "Hello im a programmer"
i want to try and split Word by the spaces, so split Word 2 maybe gives 'im' ?
-
Jan 17th, 2006, 11:04 PM
#2
Addicted Member
Re: splitting a string up
Last edited by SpS; Jan 17th, 2006 at 11:13 PM.
#Appreciate others by rating good posts !!
#The Software Peter Principle is in operation when unwise developers "improve" and "generalize" the software until they themselves can no longer understand it, then the project slowly dies.
#People who are still ignorant of their ignorance are dangerous.
-
Jan 18th, 2006, 04:17 AM
#3
Hyperactive Member
Re: splitting a string up
Here you go try this
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
char str[] = "Hello; im; a; programmer;";
char *StrPtr = NULL;
StrPtr = strtok( str, ";" );
while( StrPtr != NULL ) {
cout << StrPtr << endl;
StrPtr = strtok ( NULL, ";" );
}
system("PAUSE");
return 0;
}
When your dreams come true.
On error resume pulling hair out.
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
|