我正在使用的语言是 C。
我正在尝试混合使用内置的 c 字符串函数来获取标记列表(空格分隔)并将其“转换”为由引号分隔的标记列表。
像一个字符串
回声“你好 1 2 3 4”测试 test2
转换为
[回声] [“你好] [1] [2] [3] [4”] [测试] [测试2]
然后我使用我的代码(在底部)尝试将其转换为类似
[回声] [你好 1 2 3 4] [测试] [测试2]
由于某种原因,引用语句中的第二个“令牌”被覆盖。这是在令牌列表上运行并将其转换为新的代码片段。
88 for (int i = 0; i < counter; i++) {
89 if ( (strstr(tokenized[i],"\"") != NULL) && (inQuotes == 0)) {
90 inQuotes = 1;
91 tokenizedQuoted[quoteCounter] = tokenized[i];
92 strcat(tokenizedQuoted[quoteCounter]," ");
93 } else if ( (strstr(tokenized[i],"\"") != NULL) && (inQuotes == 1)) {
94 inQuotes = 0;
95 strcat(tokenizedQuoted[quoteCounter],tokenized[i]);
96 quoteCounter++;
97 } else {
98 if (inQuotes == 0) {
99 tokenizedQuoted[quoteCounter] = tokenized[i];
100 quoteCounter++;
101 } else if (inQuotes == 1) {
102 strcat(tokenizedQuoted[quoteCounter], tokenized[i]);
103 strcat(tokenizedQuoted[quoteCounter], " ");
104 }
105 }
106
107 }