#include <stdio.h>
#include <stdlib.h>
char * get_string(char str[])
{
printf("Input a string: ");
return gets(str);
}
main(){
int degrees;
char scale;
int return_value;
char string[1023];
while(1){
printf("Please type in a string like 20C or 15F\n");
printf("Use control-C to quit\n");
get_string(string);
return_value = sscanf(string,"%d%c",°rees, &scale);
if (return_value != 2){
printf("There's a mistake in your input. Try again.\n");
continue;
}
if (( scale == 'f')|| (scale == 'F'))
printf("%s is %dC\n",string,((degrees-32)*5)/9);
else
if (( scale == 'c')|| (scale == 'C'))
printf("%s is %dF\n",string, (degrees*9)/5+32);
else{
printf("Unable to determine whether you typed C or F\n");
printf("Try again.\n");
}
}
}