If input
is the string !c
and you are looking to match that against the line 2 - cd
, you will have to be careful. strcmp
will definitely not work, as it will only return success if the two strings it is comparing are exact matches.
In order to test whether one string (cd
) starts with another string (c
), you want to use strncmp()
, which will take a limit on the number of characters to compare.
Also: you will need to be careful to start comparing from the second character of input
(skipping the !
) and from the fifth character of currLine
(skipping the 2 -
characters).
This should get you there:
while (fgets(currLine, sizeof currLine, fileRead) != NULL) {
printf(input+1);
printf(currLine);
if (strncmp(input + 1, currLine + 4, strlen(input)-1) == 0) {
printf("%s\n", currLine);
parse(currLine);
}
}