请教各位大神~关于strtok的参数问题

RuHua27 RuHua27 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
为什么不能用指向“字符串“常量的指针呢?具体见代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void print_tokens(char *line)
{
static char whitespace[] = " \t\f\r\v\n";
printf("%s\n", line);
char *token;

for ( token = strtok(line, " "); token != NULL;
token = strtok(NULL, whitespace) )
printf("%s\n", token);
}

int main()
{


char input[] = "aa bb cc dddd fsd123 134 fwe";
print_tokens(input);//如果把这里的input换成"aa bb cc dddd fsd123 134 fwe"程序就会崩溃

return 0;
}
...全文

相关推荐

strtok的缺陷,使用strtok_s函数更新安全度

strtok的缺陷,使用strtok_s函数更新安全度 #include "stdafx.h" #include "Windows.h" #include #include using namespace std; char string1[] = "A string\tof ,,tokens\nand some more tokens"; char string2[] = "Another string\n\tparsed at the same time."; char separators[] = " ,\t\n"; char *token1, *token2, *next_token1, *next_token2; int main(void) { cout << "Tokens:" << endl; // establish a string and get the first token: token1 = strtok_s(string1, separators, &next;_token1); token2 = strtok_s(string2, separators, &next;_token2); // while there are tokens in "string1" or "string2" while ((token1 != NULL)) { // get the next token: if (token1 != NULL) { cout << token1 << endl; token1 = strtok_s(NULL, separators, &next;_token1); OutputDebugString(_T(token1)); } } while ((token2 != NULL)) { // get the next token: if (token2 != NULL) { cout << token2 << endl; token2 = strtok_s(NULL, separators, &next;_token2); OutputDebugString(_T(token2)); } } Sleep(3000); system&#40;"pause"&#41;;

yelenn1115

C语言切割多层字符串(strtok_r strtok使用方法)

主要介绍了C语言切割多层字符串的方法,说了strtok的弱点,使用strtok_r的方法

weixin_38727928

strtok函数的使用示例

今天小编就为大家分享一篇关于strtok函数的使用示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

weixin_38681318

strtok函数的用法 strtok函数的用法

strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strtok函数的用法strto

「已注销」

C++中strtok()函数的用法介绍

函数原型:char *strtok(char *s, const char *delim);Function:分解字符串为一组字符串。s为要分解的字符串,delim为分隔符字符串。Description:strtok()用来将字符串分割成一个个片段。参数s指向欲分割的字符串,参数delim则为分割字符串,当strtok()在参数s的字符串中发现到参数delim的分割字符时 则会将该字符改为\0 字符。在第一次调用时,strtok()必需给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回被分割出片段的指针。 代码如下:#include <iostream>   #inclu

weixin_38667920
评论 2
收藏 已收藏
分享
返回顶部
RuHua27
C语言 70,039 成员 243,237 内容