Beginner at C here.
I understand that strstr()
can be used for finding if strings contain a certain substring and that printf()
can display colored output (as explained here: stdlib and colored output in C).
What I am trying to figure out is a simple way to color only the matching portion of the string (like in grep
), since strstr()
returns the entire part of the line from the match. Alternatively I could print the entire matching line but that would end up with the entire line being colored.
Assuming that bold = coloring for illustrative purposes, my desired result when searching for the substring elephant is:
this is an elephant's tusk
printf + coloring the strstr()
output gives:
elephant's tusk
and of course printf + coloring the entire matched line gives:
this is an elephant's tusk
Thank you in advance for the help.