exercises/ex02.5/find_track.c
void find_track_regex(char pattern[], int szof)
{
    char * regexString = pattern;
    regex_t regexComp;
    char msgbuf[100];

    if (regcomp(&regexComp, regexString, 0)){
      fprintf(stderr, "Could not compile regex\n");
      exit(1);
    }
    for (int i=0; i<NUM_TRACKS; i++){
      int reti = regexec(&regexComp, tracks[i], 0, NULL, 0);
      if (!reti){
        printf("Track number %d, track %s\n", i, tracks[i]);
      } else if (reti == REG_NOMATCH){
        continue;
      } else {
        regerror(reti, &regexComp, msgbuf, sizeof(msgbuf));
        fprintf(stderr, "Regex match failed: %s\n", msgbuf);
        exit(1);
      }
    }
    regfree(&regexComp);
}
// Finds all tracks that match the given pattern.
//pattern: the pattern to be searched
// szof: the length of pattern
//
// Prints track number and title. Throws error if match fails
Finds all tracks that match the given pattern.
pattern: the pattern to be searched
szof: the length of pattern

Prints track number and title. Throws error if match fails
Finds all tracks that match the given pattern . pattern : the pattern to be searched szof : the length of pattern Prints track number and title . Throws error if match fails
void find_track_regex(char pattern[], int szof)
{
    char * regexString = pattern;
    regex_t regexComp;
    char msgbuf[100];
    if (regcomp(&regexComp, regexString, 0)){
      fprintf(stderr, "Could not compile regex\n");
      exit(1);
    }
    for (int i=0; i<NUM_TRACKS; i++){
      int reti = regexec(&regexComp, tracks[i], 0, NULL, 0);
      if (!reti){
        printf("Track number %d, track %s\n", i, tracks[i]);
      } else if (reti == REG_NOMATCH){
        continue;
      } else {
        regerror(reti, &regexComp, msgbuf, sizeof(msgbuf));
        fprintf(stderr, "Regex match failed: %s\n", msgbuf);
        exit(1);
      }
    }
    regfree(&regexComp);
}
void find_track_regex ( char pattern [ ] , int szof ) { char * regexString = pattern ; regex_t regexComp ; char msgbuf [ 100 ] ; if ( regcomp ( & regexComp , regexString , 0 ) ) { fprintf ( stderr , " \n " ) ; exit ( 1 ) ; } for ( int i = 0 ; i < NUM_TRACKS ; i ++ ) { int reti = regexec ( & regexComp , tracks [ i ] , 0 , NULL , 0 ) ; if ( ! reti ) { printf ( " \n " , i , tracks [ i ] ) ; } else if ( reti == REG_NOMATCH ) { continue ; } else { regerror ( reti , & regexComp , msgbuf , sizeof ( msgbuf ) ) ; fprintf ( stderr , " \n " , msgbuf ) ; exit ( 1 ) ; } } regfree ( & regexComp ) ; }
Finds all tracks that match the given pattern.
Finds all tracks that match the given pattern .