char str1 [] =
"{ 'Carl Maria von Weber', 'weber', 8 }{ ' Maria von Carl Weber ', 'weber', 1 }
"
"{ 'Carl Weber Maria von', 'weber', 2 }
"
"{ 'Carl-Maria von Weber', 'weber', 4 }
"
"{ 'Chuck Norris', 'norrischuck', 100 }";
If I have such a string, how can I store it in the field, so I should
char field [0] = Carl Maria von Weber
char field [1] = weber
char field [2] = 8
I created the following code, which also stores {}, characters in the field. Can I edit the string str before using the function so that the characters {},? are removed. Or am I wrong about this and do you know any other procedure?
char *src;
char a[2000];
src=a;
fscanf(fp,"%[^"]",src);
//printf("%s
",src);
int count=1000;
char output[1000][1000];
int i = 0;
while (i < count) {
const char *start;
int len;
while (isspace((unsigned char)*src))
src++;
if (*src == '')
break;
if (*src == ''') {
start = ++src;
len = strcspn(src, "'");
src += len;
if (*src == ''')
src++;
} else
if (*src == '"') {
start = ++src;
len = strcspn(src, """);
src += len;
if (*src == '"')
src++;
} else {
start = src;
len = strcspn(src, " fv
");
src += len;
}
snprintf(output[i], sizeof(output[i]), "%.*s", len, start);
i++;
}
question from:
https://stackoverflow.com/questions/66068052/c-format-string-to-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…