[英]Removing First and Last Character from string array
你好我試圖找到一種方法來刪除字符串數組的第一個和最后一個字符。
我的數據洞察數組是這樣的:
“時間1”:
“3.0”
等等
我試圖專門刪除雙引號和字符:我應該使用什么?
char item[100];
char LastArray[1000];
while (NewMixedArray[i] != NULL)
{
sscanf (NewMixedArray[i],"\"%99[^\"]", item);
LastArray[i]=item;
printf("%d %s\n",i,LastArray[i]);
i++;
}
i=0;
while ( LastArray[i] != NULL)
{
printf("DONE: %d %s\n",i,LastArray[i]);
i++;
}
在第二個 printf 上,我只得到最后一個值。
https://i.imgur.com/H2OFz1Q.png
我發現我的問題我使用了命令
LastArray[i] = strdup(item); 因為我的 LastArray 是一個指針數組。
#include <stdio.h>
#include <string.h>
int main() {
char string[1000], result[1000];
strcpy(string, "\"Time1\":");
printf("\nInitial String : %s", string);
int i;
int c = 0;
do {
if (string[i] != '\"' & string[i] != ':') {
result[c] = string[i];
c++;
}
i++;
} while (string[i] != '\0');
printf("\nResult : %s\n", result);
return 0;
}
結果
$ ./ss
Initial String : "Time1":
Result : Time1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.