Code:
EXAMPLE
The following program uses nested loops that employ strtok_r() to break
a string into a two-level hierarchy of tokens. The first command-line
argument specifies the string to be parsed. The second argument speci-
fies the delimiter character(s) to be used to separate that string into
"major" tokens. The third argument specifies the delimiter charac-
ter(s) to be used to separate the "major" tokens into subtokens.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[])
{
char *str1, *str2, *token, *subtoken;
char *saveptr1, *saveptr2;
int j;
if (argc != 4) {
fprintf(stderr, "Usage: %s string delim subdelim\n",
argv[0]);
exit(EXIT_FAILURE);
}
for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) {
token = strtok_r(str1, argv[2], &saveptr1);
if (token == NULL)
break;
printf("%d: %s\n", j, token);
for (str2 = token; ; str2 = NULL) {
subtoken = strtok_r(str2, argv[3], &saveptr2);
if (subtoken == NULL)
break;
printf(" --> %s\n", subtoken);
}
}
exit(EXIT_SUCCESS);
} /* main */
An example of the output produced by this program is the following:
$ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/'
1: a/bbb///cc
--> a
--> bbb
--> cc
2: xxx
--> xxx
3: yyy
--> yyy
Die Strings hier sind doch keine Arrays?!? (Hab mal fett markiert was ich meine)
Hier mal noch mein Problemfall:
Code:
#include <stdio.h>
#include <string.h>
void my_function(char string[][])
{
printf("%s\n",string[1]);
}
int main()
{
char test[3][8];
test[1][0]='T';
test[1][1]='E';
test[1][2]='S';
test[1][3]='T';
test[1][4]='\0';
printf("%s\n",test[1]);
}
Lesezeichen