I'm fairly new to all of this and I somehow can't seem to find a solution. Although I have no syntax errors, the program doesn't work as its supposed to.
I want the users to input two firmnames [int read ()] which get saved under the char arrays x and y. From there I want to compare them both if they are equal or not [int equal()]. After that, if they are equal, I want to print out accordingly[int stringconcatenate()]
I want **read() ; equal() ; stringconcatenate() to be connected with the main program and work accordingly.
I'm trying to take the entered "firmnames" and then save them under the array name x and y. (which doesn't work as it should).. Am I missing something?
this is what I get if I enter "test" for both firmnames:
Please type in Firmname 1: test
Please type in Firmname 2: test
Strings are unequal.
a & ³■a are different.
Any tips are very much appreciated. Btw, I'm not allowed to use strcmp, hence my unorthodox code.
#include <stdio.h>
#include <ctype.h>
int read (){
char x[50];
char y[50];
printf("Please type in Firmname 1:\t");
scanf("%s", &x);
printf("Please type in Firmname 2:\t");
scanf("%s", &y);
}
int Equal (char x[], char y[]){
char *p1,*p2;
int f = 0;
p1=x;
p2=y;
while (*p1!= '\0' || *p2!='\0'){
if(*p1 != *p2){
f=1;
break;
}
p1++;
p2++;
}
if (f==0)
printf("\nStrings are equal.\n");
else
printf("Strings are unequal.");
}
int stringconcatenate(char x[], char y[]){
char *p1,*p2;
p1=x;
p2=y;
if (*p1==*p2){
printf ("\n %s is the only one.", x);
}
else
printf ("\n %s & %s are different.", x, y);
return 0;
}
int main(){
char s1[50], s2[50];
printf("Program Compare\n\n");
read ();
Equal (s1, s2);
stringconcatenate(s1, s2);
return 0;
}