好的,所以我理解strtok会修改它的输入参数,但在这种情况下,它会将输入字符串折叠成只有第一个标记.为什么会发生这种情况,我该怎么做才能解决这个问题?(请注意,我不是在谈论变量"temp",它应该是第一个令牌,而是变量"input",在一次调用strtok后变为"this")
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
char input[]="this is a test of the tokenizor seven";
char * temp;
temp=strtok(input," ");
printf("input: %s\n", input); //input is now just "this"
}
Run Code Online (Sandbox Code Playgroud) 我需要查找char数组是否以"ADD"开头.我知道使用strcmp(),但我不知道如何获得前三个字符.我真的很讨厌使用c-strings.我怎样才能像一个char数组一样char buffer[1024]?
如果我有一个字符串,例如命令的字符串
回声'foobar'|猫
有没有一种好方法可以让我获得引号之间的文本(“foobar”)?我读到可以scanf在文件中执行此操作,是否也可以在内存中执行此操作?
我的尝试:
char * concat2 = concat(cmd, token);
printf("concat:%s\n", concat2);
int res = scanf(in, " '%[^']'", concat2);
printf("result:%s\n", in);
Run Code Online (Sandbox Code Playgroud)