I'm doubtful in the following exercise:
Write a C program that receives two strings via standard input and whether the second string is contained in the first string, that is, if the second string is a segment of the first. You may consider, in your program, that the second string is always smaller than the first, and that the strings have a maximum of 100 characters. Here is an example of entrance and exit. What is underlined was provided by the user.
- String 1: program
- String 2: gram
The second string is contained in the first!
The code I made, always says "The second string is contained in the first string". Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char**argv){
char string1[101];
char string2[101];
int i, x;
printf("Forneca a string 1: \n");
scanf("%s",string1);
printf("Forneca a string 2: \n");
scanf("%s",string2);
x=strlen(string2);
for(i=0; i<x; i++){
if(string2[i]=string1[i]){
printf("A segunda string esta contida na primeira. \n");
break;
}
}
return 0;
}