Hi all, italian newbie here. Sorry for my bad english and for my "bad C", I'm trying to learn both.
The program I'm trying to write compare two string and define if the second one is included in the first one.
Code:
#include <stdio.h>
#include <string.h>
#define FRASE 10
void controlloStringhe (char* string1, char* string2, int dimensione, int parolaIntera);
int main()
{
char string1 [FRASE];
char string2 [FRASE];
printf("Inserire le due parole da controllare.\n");
scanf("%s %s", string1, string2); //read the two string without checking their lenght, i want to do this later by myself, that's not the actual problem
printf("Controllo se la seconda è contenuta nella prima...\n");
controlloStringhe(string1,string2,strlen(string2)+1,strlen(string1)+1);
return 0;
}
void controlloStringhe(char* string1, char* string2, int dimensione, int parolaIntera){
int i;
for(i=0;i<parolaIntera;i++){
string1+=i;
if(strncmp(string1,string2,dimensione)==0){
printf("La seconda stringa è contenuta nella prima.\n"); //the second one is included in the first one
return;
}
}
printf("La seconda stringa non è contenuta nella prima.\n"); //the second one is not included in the first one
}
e.g: if I write HELLO and ELL, the program should tell me that the second string is included in the first... while HLLO is not.
now, trying some word, that's the answers:
funzione funzione
the second is included
funzione unzione
the second is included
funzione zione
the second is included
funzione funzion
the second is NOT included
funzione ciao
the second is not included
funzione unzion
the second is not included
funzione nzione
the second is not included
it is clear to me that there is some problem, don't know where...