I'm back at it after a few weeks of not actually coding. I'm reading plenty, but that is no substitute for hitting a keyboard.
The plan is to prove my understanding of program structure and passing things to functions for manipulation.
Overall, the plan is this:
Be presented with some options (1,2,3,4, etc) and a big array of text (Desiderata, for now). Each option will perform a task and return the result. The first few obvious ones are a histogram of letters in the text (which I touched on in my prior post), sorting the words/line/etc by length, removing/inserting characters, and other common beginner things you're supposed to be able to do with text in an array.
The first hurdle is reading in the options. I remember that C++ has the CIN function, but C itself doesn't seem to have such a clear method of taking input from the keyboard. It does have getchar(), but it seems like overkill. Since I can't find any alternative (none anyways in my book yet) I'll just go with overkill.
Here is my first test to make sure that I understand what getchar() is doing:
main()
{
char character;
int integer;
integer = character = getchar();
printf("character is %c\n", character);
printf("integer is %i\n", integer);
}
The output is as I expect. If I run the program, it holds and waits for me to type in a character and hit enter. so...
chris@chris:~/learningc$ ./getchartests
f
character is f
integer is 102
No surprises... for a change.
The next move is to write a program that takes in this character (in a slightly better formatted way) and shuffles it through your standard switch/case statements. I guess I could do a big if/then block, but there will be plenty of those to come.
No comments:
Post a Comment