分割字符串
问题描述:
大家好!
在我的程序中,我定义了字符串的二维数组,如下所示
Hey guys!
In my program I have defined 2-D array of string as follows
char str[10];//normal character array
char word[10][100]={
"apple-a fruit","elephant-an animal","cricket-a game"}; //2-D array
如果要处理苹果水果"中的字符串苹果"
那么我应该如何在str中存储苹果".
然后再次处理大象动物"中的大象",str应该不包含任何内容.
If I want to process a string "apple" from "apple-a fruit"
then how should I store "apple" in str.
and then again for processing "elephant" from "elephant-an animal", str should contain nothing.
How should I do it?
答
您可以尝试的一种方法是使用strtok().这是一个示例 [
One method you can try would be to use strtok(). Here''s an example[^] of it''s use.