home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!seas.smu.edu!pedersen
- From: pedersen@seas.smu.edu (Ted Pedersen)
- Subject: HELP with scanf/getchar!
- Message-ID: <1992Nov9.162547.11163@seas.smu.edu>
- Sender: Ted Pedersen
- Nntp-Posting-Host: rapid_f.seas.smu.edu
- Organization: SMU School Of Engineering and Applied Science
- Date: Mon, 9 Nov 1992 16:25:47 GMT
- Lines: 71
-
-
- The following is an annoying little problem that I just can't figure
- out. I'm trying to get the program to prompt me for how many
- characters I want to enter and then once I have said how many
- characters I want I want the program to ask me to input those
- characters.
-
- What really happens is that it asks me how many characters I want. I
- input that and then my program sits. When I input the appropriate
- number of characters the program goes ahead and prints out the message
- asking for characters and then runs the program ok.
-
- It seems like this is running out of order. Anyone have any idea as to
- what might be going on?
-
- Thanks,
- Ted Pedersen
- --------------------------------------------------------------------
- #include <stdio.h>
- #include <ctype.h>
-
- #define SIZE 128
-
- int storage[SIZE];
-
- void count_char (void);
-
-
- void count_char (void) {
- char character;
- int count,
- loop,
- output;
-
-
- printf ("Enter number of characters you want : ");
- scanf ("%d\n", &count);
- printf ("Enter your characters :");
- for (loop = 0; loop < count; loop++) {
-
- character = getchar();
- storage[character]++;
-
- }
-
- for (output = 0; output < SIZE; output++) {
- if (storage[output] >= 1) {
- printf ("\n %c (ascii code = %d) occurs %d times",
- output,
- output,
- storage[output]);
- }
- }
- }
-
- main () {
- count_char ();
- }
- ------------------------------------------------------------------
- %a.out
- Enter number of characters you want : 4
- abcd
- Enter your characters :
- a (ascii code = 97) occurs 1 times
- b (ascii code = 98) occurs 1 times
- c (ascii code = 99) occurs 1 times
- d (ascii code = 100) occurs 1 times
-
- %exit
-
-
-