题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <stdio.h> #include <string.h> int main() { int n = 0; char str[1000] = {0}; while (gets(str)) { int n1 = strlen(str); int i = 0; int flag = 0; char* p = str; char*strhead[100]; strhead[0] = str; while (*p != '\0') { if(!flag){ if(*p==' ' && *(p+1)!='"') { i++; strhead[i] = p+1; *p = '\0'; p++; }else if(*p==' '&&*(p+1)=='"') { i++; flag = 1; strhead[i] = p+2; *p='\0'; p++; } } else if(flag == 1) { if(*p == '"') { flag =0; *p='\0'; } } p++; } printf("%d\n",i+1); for(int j=0;j<=i;j++) { printf("%s\n",strhead[j]); } } }