Locate last occurence of substring
#include <publib.h> char *strrstr(const char *str, const char *pat);
strrstr finds the last occurence of the string pat in the string str. The terminating '\0' characters are not compared.
strrstr returns a pointer to the first character of the substring, or NULL if the substring is not found.
To print out everything on each line starting with the last occurence of "/* " on each line, you might use the following code:
#include <stdio.h> #include <publib.h> int main(void) { char *p, line[512]; while (fgets(line, sizeof(line), stdin) != NULL) { p = strrstr(line, "/* "); if (p != NULL) printf("%s", p); } return 0; }
Lars Wirzenius ([email protected])