Yes no string in C -
this question has answer here:
- how compare strings? 6 answers
i've searched forums, , can't seem find answer suitable specific problem (i tried google well). seem having issue comparing strings ("yes", "yes", "no", "no") correctly. tried if else originally, think while loop more efficient. suggestions?
#include <stdio.h> #include <stdlib.h> #include <string.h> double far = 0; double cel = 0; double uservalue = 0; double endresult = 0; int choice; char *decision = ""; int main() { conversion(); return 0; } conversion() { printf("please enter 1 celsius fahrenheit conversion or\n 2 fahrenheit celsius conversion\n"); scanf("%d", &choice); if(choice == 1) { printf("please enter value celsius. example 32 or 32.6\n"); scanf("%lf", &uservalue); endresult = (uservalue * (9.0/5.0) + 32); printf("%lf\n", endresult); yesorno(); } else printf("please enter value fahrenheit. example 212 or 212.6\n"); scanf("%lf", &uservalue); endresult = (uservalue -32) * (5.0/9.0); printf("%lf\n", endresult); yesorno(); } yesorno() { printf("do want continue? enter yes or no\n"); scanf(" %s", &decision); while(decision == "yes" || decision == "yes") { conversion(); } exit(0); }
c doesn't have strings. have use function strcmp() compare string literals and/or null-terminated character arrays.
decision == "yes"
should be
strcmp(decision,"yes") == 0
Comments
Post a Comment