请问怎么用c语言从一段不规则字符串中把两个引号之间的字符读取到一个数组里

如题所述

调用 sscanf() 即可。读法:跳过第一个引号以前的字符,读下面字符,直到下一个引号前为止。
#include <stdio.h>
int main()
{
char s[100]="abdc12\"3456 xyz-%%\"%ABe";
char s2[100];
int i;
sscanf(s,"%*[^\"]\"%[^\"]",s2); // 关键的语句和格式在此行
printf("%s\n",s2);
return 0;
}

自己写语句,一个字符一个字符判别也可。
char s[100]="abdc12\"3456 xyz-%%\"%ABe";
char s2[100];
int i=0,n=0;

while (s[i]!='"' && s[i]!='\0' )i++;
while(1){i++;
if (s[i]!='"') s2[n++]=s[i]; else break;
}
printf("%s\n",s2);
温馨提示:答案为网友推荐,仅供参考