He while
tells me that the comparison does not exist
#include <stdio.h>
int main() {
int n, e, op, edad;
char sexo[1], res[2];
n = 0;
edad = 0;
do {
n = n + 1;
printf("Edad del conductor\n");
scanf("%d", &e);
printf("Sexo de conductor F= femenino, M= masculino\n");
scanf("%s", sexo);
printf("1 si es capital y 2 otra parte del estado\n");
scanf("%d", &op);
if (edad < 30) {
edad = edad + e;
}
printf("desea ingresar otro usuario? Si o No?\n");
scanf("%s", res);
} while (res != "No");
edad = edad / n;
printf("%d", edad);
return 0;
}
The thing is that in C you cannot compare strings using the operators
==
, nor!=
will they only compare the pointers of both.You should use a function to compare like
strcmp
The function returns
0
when they are equal.From your comments, if you need to manipulate a single character then you don't need to use functions for string and you could change your program to something like this:
Notice that it
res
is now declared aschar
without[]
.scanf
now use the format%c
to read a single character and'N'
use single quotes'
not"
to indicate that it is not a string.It is convenient to use functions for this, such as:
But if we want to see an array as such, arrays in general...
Arrays as a whole are compared value by value, index by index.
In C, character strings end with the character '\0', which indicates that at its position (and from its position) there are no more characters in the string.
In case we want to implement a function in C to compare character strings in character arrays, I suggest this code..
Note: By the way, at the time of a keyboard input, keep in mind that scanf does not support spaces, if we want spaces to be supported, we have to use
gets(arrayDeCaracteres);