The task is for the program to read acii signs, find among them the values belonging to the Celsius scale and translate them into Fahrenheit values. For example, if 9237492572vcs 100C is msdaa aw 0C, then only 100 ° C should be considered and output 212F 32F. Values to the input are randomized. It is forbidden to use arrays, pointers and explicit numeric codes of ascii-characters
#include <stdio.h> #include <stdlib.h> int c_f(int celsius) { return ((celsius * 9) / 5) + 32; } int in_alphabet(char c) { return (c >= '0' && c <= '9') || (c == 'C'); } int main(void) { char symbol; int fahrenheit; int state = 1; char celsius; while ((symbol = getchar()) != EOF) { switch(state) { case 1: if (in_alphabet(symbol)) { scanf("%d", &celsius); fahrenheit = c_f(celsius); state = 1; } else if (!in_alphabet(symbol)) { state = 1; } printf("%d%s", fahrenheit, "F"); break; } } return 0; } Now the loop goes through each character and outputs 32F instead. Instead of reading, celsius assigns it to 0. The cycle ignores zeros, at 100 ° C passes 1 and C. How can I fix this? How to make the cycle read the word completely, while not in the 16th number system? (Now 100C - perceives as 4108)
state = 1assignments, if thestatefrom the very beginning, 1 t always and everywhere becomes onlystate = 1? - AnT