code_junkie

Splitting a string by space in C

Nov 12th, 2011
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. char buffer[2048];
  2. char *sp;
  3.  
  4. /* read packet into buffer here, omitted */
  5.  
  6. /* now find that space. */
  7. sp = strchr(buffer, ' ');
  8. if(sp != NULL)
  9. {
  10. /* 0-terminate the first part, by replacing the space with a ''. */
  11. *sp++ = '';
  12. /* at this point we have the first part in 'buffer', the second at 'sp'.
  13. }
Add Comment
Please, Sign In to add comment