I would like to print the sub expression of match "bytes". I have simplified this example so I can debug other components of my code:
char *bytes="[[:print:]]*\(bytes\)";
regex_t compiled;
regmatch_t matches[2];
char currentLine[512];
fgets(currentLine, 512, ifile);
regcomp(&compiled, bytes, REG_EXTENDED);
if(regexec(&compiled, currentLine, 2, matches, 0)==0){
printf("%s\n", bytes+matches[1].rm_so);
}
Where
currentLine= "Free Memory: 5062026704 bytes (79%)";'
takes place after the fgets.
The printed line I receive is an unformatted printf statement from another function - one which runs after this one. I have a few different ideas on where my problem might be(regex syntax, memory allocation, usage of regmatch_t), and I have been trying different combinations of solutions all morning but to no avail as of yet.
How can I correctly print the matched substring?