I want to start a program of Y and N Q&A.
#include <stdio.h>
#include <stdlib.h>
int main(){
char answer[256];
do {
print("\nDo you want to delete yourself of the record?\n");
scanf("%s", answer);
printf("%s", answer);
}while(answer != "Y" || answer != "N")
;
return 0;
}
As you can see, I declared a variable of type char of 256 elements, and then using scanf I recorded the user input and store it in answer. Then the loop will be keeping asking as long the user enters either an uppercase Y or N. The problem is that with this implementation the program keeps asking even if I enter a Y or N. Should I change the char declaration to a single character? I already tried this:
#include <stdio.h>
#include <stdlib.h>
int main(){
char answer;
do {
print("\nDo you want to delete yourself of the record?\n");
scanf("%c", answer);
printf("%c", answer);
}while(answer != 'Y' || answer != 'N')
;
return 0;
}
but I received a warning:
warning: format '%c' expects argument of type 'char *', but argument 2 has type int' [-Wformat=]
scanf("%c", answer);
Does anyone has a clarification for this problem?