How can I check if a string contains a specific substring along with any additional text (e.g., "hello <any text e.g., meatballs>") in C? Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../include/ANSI-color-codes.h"
int main(int argc, char* const argv[]) {
if (argc != 2) {
printf(BLU "VPWL (Very Powerful Web Language) \nyou build big bundle Small\n" reset);
return 1;
}
FILE *fptr;
fptr = fopen(argv[1], "r");
char FileString[2097152]; // 2 MB, approximately
while (fgets(FileString, 2097152, fptr)) {
printf("%s", FileString);
if (strstr(FileString, "<button('') />")) {
// Code for processing the matching line
}
}
fclose(fptr);
return 0;
}
I would like to know how to properly check if the string in FileString contains the substring <button('') /> along with any additional text in between the Quotes (not on the beginning and end). Any help or guidance would be appreciated. Thank you!
i tried %s it did not work
There is no standard regular expression package in C, for your purpose you can write an ancillary function that finds the 2 substrings: