Text Input and Data Conversion
description pending....
text-entry.c
#include <stdio.h>
#include <stdlib.h>
int main() {
//menu based on a single character
char userChar;
puts("select options [A] or [B]");
userChar = getc(stdin);
if(userChar == 'A'){
puts("You selected option A!");
} else if(userChar == 'B'){
puts("You selected option B!");
} else {
puts("error, unknown input");
printf("userChar Code = %d\n", userChar);
}
//fgets - "file get string"
puts("type in some text or words:");
char userText[100];
fgets(userText, 100, stdin);
printf("You typed in this: %s \n", userText);
char firstEntry = userText[0];
printf("the first character is %c \n", firstEntry);
//taking user input as text, and converting to a floating point number
// atof() "string to float"
puts("type in a number, this will multiply by 5:");
char userText[100];
fgets(userText, 100, stdin);
double userValue = atof(userText);
double result = userValue * 5;
printf("here's your value muliplied by 5: %f \n", result);
}