I'm stuck again, why am I unable to display the last character of the sub-string when the sub-string is located at the end of the string? I thought a NULL character is automatically appended to the array input ?
Also it seems that the search result won't capture the puntuation in the search. A search of sub-string "Hello!" in the string "Hello! World!" will only return 'Hell' (What an irony!!)
Is there anyway to achieve your guys level... any tips...Code:#include <stdio.h> #include <ctype.h> #include <string.h> void searchstr (char str[]); main() { char str[100]; printf ("Enter the String :"); fgets (str, sizeof str, stdin); searchstr (str); return 0; } void searchstr (char str[]) { char substr[100]; printf ("Enter the string you want to find: "); fgets (substr, sizeof str, stdin); if (strstr(str, substr)) printf ("the substring '%s' is found !!!", substr); }
And also curious to find out the market protienal for C programming... Is it still in demand in the market ?



LinkBack URL
About LinkBacks





) fgets() add's \n at the end of the string, you should check if you have one like that and then remove.
But but.... A search of sub-string "Hello!" (includind the !) in the string "Hello! World!" will only return 'Hell' and the Hello is at the begning of the string, or is it the strstr function can only search for character and not the puntuation?? But, then again... if the punchutation is in the middle of the sub-string, it will still able to display without eating up the word..... I tried before....