I have the following exercise:
Implement a function that is passed as input to two character strings. The function must return a 1 if the strings are equal, but it will return a 0 (it can not use specific functions of C).
This is what I tried:
#include<stdio.h>
char cadenas (char cad1[100],char cad2[100] ) {
int i;
for (i=0;i<100;i++){
printf ("\nintroduzca el caracter %s de la cadena");
scanf ("%s", cad1[i]);
}
for (i=0;i<100;i++) {
printf ("\nintroduzca el caracter %s de la cadena");
scanf ("%s",cad2[i]);
}
if (cad1==cad2) {
printf ("las cadenas %s son iguales");
return 1;
What happens is that when compiling I get several warnings, I do not know what errors the code could have:
ejexamen.c: In function ‘cadenas’:
ejexamen.c:22:11: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
printf ("\nintroduzca el caracter %s de la cadena");
^
ejexamen.c:23:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
scanf ("%s", cad1[i]);
^
ejexamen.c:30:12: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
printf ("\nintroduzca el caracter %s de la cadena");
^
ejexamen.c:31:10: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
scanf ("%s",cad2[i]);
^
ejexamen.c:38:12: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat=]
printf ("las cadenas %s son iguales");
^
ejexamen.c:42:8: error: expected ‘}’ before ‘else’
else {
^
Thanks