/*2、实现一个字符串拆分的功能, 分隔符为 ? int split(char *str, char **p); 第一个参数为要拆分的字符串,第2个参数保存数据,返回拆分了多少字段。 示例: char *arr[10]; int n = split(&quot;AB?EEEEE?BBB&quot;, arr); for (int i = 0; i < n; ++i) cout << arr[i] << endl; 输出: AB EEEEE BBB 内存自己释放*/ #include#include  #include  using namespace std; int split(char *str, char **p){ int count = 0; char**q = NULL; char *token = strtok_s(str, &quot;?&quot;, q); while(token != NULL){ *(p + count) = token; token = strtok_s(str, &quot;?&quot;, q); count++; } return count; } int main(){ char str[100] = { 0 }; cin >> str; char **p = new char*[10]; memset(*p, 0, 80); int n = split(str, p); for(int i = 0; i < n; i++){ cout << *(p + i) << endl; } delete [] p; return 0; }
2024-03-07
在牛客打卡10天,今天也很努力鸭!
全部评论

相关推荐

点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务