Hi all.
I am trying to create a program which will compare 2 strings.Find the first character which is equal between them and save it on the third string.If it doesnt find any character it will save a -1.
My code always prints a -1...
Here is my code,I dont know what I am doing wrong.If anybody has any idea,plz help me.
Code:#include <stdio.h> #define MAX 1000 void any(char s1[],char s2[],char s3[]); int main() { char string1[MAX],string2[MAX],string3[MAX]; printf("Jepni stringen 1\n"); scanf("%s",& string1); //saving string 1 printf("Jepni stringen 2\n"); scanf("%s",& string2); //saving string 2 any(string1,string2,string3); /*comparing characters from string 2 to string 1 and saving the places where they are equal on third string*/ printf("%d",string3[0]); //printing the first character of the third string return 0; } void any(char s1[],char s2[],char s3[]) { int i,j,k; k=0; for(j=0;j!='\0';j++) { for(i=0;i!='\0';i++) { if(s2[j]==s1[i]) { s3[k]=i; j++; k++; } } } s3[k]=-1; }



LinkBack URL
About LinkBacks



