hi everyone,

im searching a string using regex and it works fine...but it only returns me the first result...im trying to store all the results(indicies) in an array, and return it..

thanks for any help

Code:
int* search(char *file, char *currentSearch, char *tagType) {
	
	int error = 0;
    regex_t re;
    size_t a = 2;
    regmatch_t arrayOfMatches[1000];
	int counter=0;
	int *Matches;
    
    if (regcomp(&re, currentSearch, REG_EXTENDED|REG_ICASE) != 0) {

        return(0);      

    }

	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")){
			Matches[counter] = arrayOfMatches[counter].rm_so;
		}
		
		else{
			Matches[counter] = arrayOfMatches[counter].rm_eo;
		}
		
		if ((Matches = realloc(Matches, sizeof(int) * sizeof(Matches))) == NULL){
			fprintf(stderr, "Unable to reallocate %d bytes of memory for file\n", sizeof(int));
			exit(1);
		}
			
  	  	/* This call to regexec() finds the next match */
    	error = regexec (&re, file + arrayOfMatches[counter].rm_eo, counter, arrayOfMatches, REG_NOTBOL);
    	
		counter++;
    }
	
	regfree(&re);    
    return Matches;

}