0
Function that given a strings, prints another
As the title i Need to build a function wich given a string, if It recognizes It, prints another estabilished string. I tried using the strstr function but If in the input there's the same string 2 times, i Will get only 1 output, instead of 2 as aspected. I know i should build some sort of FOR or While structure but i Just can't find the way. Thanks to everyone Will give a hand
4 Réponses
+ 1
from function description:
The strstr() function finds the FIRST occurrence of the substring needle in the string haystack. The terminating null bytes ('\0') are not compared.
I used strtok and strcmp for this task
0
Here Is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char input[100];
fgets(input, 100, stdin);
char *Lion;
Lion = strstr(input, "Grr");
if (Lion){
printf("Lion\t");
}
return 0;
}
0
Thanks for the tip Igor, but what if I wanted to write a function instead of using One given by the string.h header?
0
You could try;)