- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- strtok question again
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:00 AM
тАО04-29-2005 07:00 AM
strtok question again
I am trying to parse an ASCII file using strtok. The trouble is some string that I am parsing contain one space and I am trying to get them all at once:
From the string:
Hello how are you
I want the following:
Hello
how
are you
In 3 different strings........
So far I am using the following code:
char* pValue;
pValue = strtok (pText, " \t");
i = 0;
do
{
pValue = strtok (NULL, " \t");
i++;
} while( (pValue != NULL) && (i < Column) );
what I get is:
Hello
how
are
you.....
In fact, I would like strtok to differ from one space to two spaces....
getting only 3 strings not 4:
For the string:
"1234 1235 152153 1 111"
I would like to get only 4 strings:
"1234"
"1235"
"152153"
"1 111"
and not
"1"
- Tags:
- strtok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:14 AM
тАО04-29-2005 07:14 AM
Re: strtok question again
Did that help?
Looks like you need to modify the loop to the
following:
do
{
if (i < Column-1)
pValue = strtok (NULL, " \t");
else
pValue = strtok (NULL, NULL);
i++;
} while( (pValue != NULL) && (i < Column) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:19 AM
тАО04-29-2005 07:19 AM
Re: strtok question again
The issue is that the single space could be anytim in the string, not only at the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:24 AM
тАО04-29-2005 07:24 AM
Re: strtok question again
// scan to correct column
char* pValue;
pValue = strtok (pText, " \t");
i = 0;
do
{
pValue = strtok (NULL, NULL);
i++;
} while( (pValue != NULL) && (i < Column) );
This doesn't seem to work...any other idea?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:30 AM
тАО04-29-2005 07:30 AM
Re: strtok question again
code as I suggested.
What is the value of Column?
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:35 AM
тАО04-29-2005 07:35 AM
Re: strtok question again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:47 AM
тАО04-29-2005 07:47 AM
Re: strtok question again
NULL terminated?
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:53 AM
тАО04-29-2005 07:53 AM
Re: strtok question again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:54 AM
тАО04-29-2005 07:54 AM
Re: strtok question again
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-29-2005 07:59 AM
тАО04-29-2005 07:59 AM
Re: strtok question again
tx