分割字符串 [英] partitioning the string

查看:116
本文介绍了分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
在我的程序中,我定义了字符串的二维数组,如下所示

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.


这篇关于分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆