Ok, I write some code for get ALL numbers from string:
Code:
int error = 0;
regex_t re;
size_t a = 2;
regmatch_t arrayOfMatches[10];
int counter=0;
int *Matches;
char currentSearch[9]="([0-9]+)";
char file[32] = "hello777world99yew 8 I8909do23!";
char tagType[6] = "start";
if(regcomp(&re, currentSearch, REG_EXTENDED|REG_ICASE) != 0)
{
printf("ERROR\n");
exit(1);
}
if((Matches = malloc(sizeof(int))) == NULL)
{
fprintf(stderr, "Unable to reallocate %d bytes of memory for current search\n", sizeof(int));
exit(1);
}
/* Finds the matches on the line */
error = regexec (&re, file, a, arrayOfMatches, 0);
/* while matches found */
while (error == 0)
{
if(strcmp(tagType,"start") == 0)
{
Matches[counter] = arrayOfMatches[counter].rm_so;
}
else
{
Matches[counter] = arrayOfMatches[counter].rm_eo;
}
/* This call to regexec() finds the next match */
counter++;
void *temp = realloc(Matches, (counter+1) * sizeof *Matches);
if (temp != NULL)
Matches = temp;
else
{
fprintf(stderr, "Unable to reallocate %d bytes of memory for file\n", sizeof(int));
exit(1);
}
error = regexec (&re, file + arrayOfMatches[counter].rm_eo, counter, arrayOfMatches, REG_NOTBOL);
printf("%i\n",arrayOfMatches[counter].rm_eo);
}
regfree(&re);
But, I can't find error in this code, in my terminal I get this:
Code:
grytskiv@ZXDSL831II:~/socket/proxy$ gcc client.c -o client && ./client
8
0
0
0
0
0
0
0
0
140
grytskiv@ZXDSL831II:~/socket/proxy$