Help needed! 
Author Message
 Help needed!

Hi, I have a problem:  how can I do to split a string in several
parts?

For example: let us suppose that we have
line[] = "Hellow computerprogrammers" and want to have "Hellow" in one
variable and "computerprogrammers" in other like
stra[] = "Hellow" and strb[] = "computer programmers".
I should be very grateful if somebody can help me. Please. Thanks.



Tue, 23 Nov 2004 10:18:31 GMT  
 Help needed!

Quote:

> Hi, I have a problem:  how can I do to split a string in several
> parts?

> For example: let us suppose that we have
> line[] = "Hellow computerprogrammers" and want to have "Hellow" in one
> variable and "computerprogrammers" in other like
> stra[] = "Hellow" and strb[] = "computer programmers".
> I should be very grateful if somebody can help me. Please. Thanks.

Have a look at the strtok function.

#include <stdio.h>
#include <string.h>

int main(void)
{
  char line[] = "Hellow computerprogrammers";
  char *token;
  char firstword[7];
  char secondword[20];
  token = strtok(line, " ");
  if(token != NULL)
  {
    strcpy(firstword, token);
    token = strtok(NULL, " ");
    if(token != NULL)
    {
      strcpy(secondword, token);
    }
  }
  return 0;

Quote:
}

--

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


Sun, 28 Nov 2004 21:11:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Urgent Help Needed-Calling the help file.

2. HELP: Need Help on Error (Undefined Symbol...)

3. HELP: Need Help on Error (Undefined Symbol...)

4. HELP - Database Setup App Help NEEDED ???

5. DLL in VC++ HELP NEEDED ! Help me

6. Help Needed (MS Help Sucks)

7. Help needed with context-sensitive help

8. desperate struct help needed

9. Help needed with embedded resource files

10. Some help needed with abstract base classes

11. Addin - Help Needed

12. Sorting DirectoryInfo - Help Needed.

 

 
Powered by phpBB® Forum Software