C-Language split string

Source: Internet
Author: User
Tags strtok

Recently in a C language topic need to use the split string, originally wanted to write their own handwriting, it will not be very troublesome, but think of other languages have a split string library function, C language how can not? So, in the online search, sure enough there is such a function, or very useful, in this summary.

1#include <stdio.h>2 3#include <string.h>4 5 intMain ()6 {7     Char inch[10000];8     CharDelims[] =" ";9     Char*result;Ten  OneFgetsinch,9995, stdin); A  -  -  theresult = Strtok (inch, delims); -      while(Result! =NULL) -     { -  +printf"%s\n", result); -  +result =strtok (NULL, delims); A     } at     return 0; -}

In the C language manual, it is easy to find out the usage of strtok, one thing to note is that, in addition to the first call, the first parameter is to pass the string to be split, and all other times null.

C-Language split string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.