I am new at C and coding in general, so please bear with me.
I am trying to create a "Keyboard testing" program where a user must populate an array by entering 1-character values in each element. The contents of the array will then be sorted and a printf will show which keys were pressed most (according to how many of each character was used). I've researched for two days to no avail (Most solutions are for C++, not C). I am working in Visual Studios. Here is what I have so far:
#define _CRT_SECURE_NO_WARNINGS
#define PAUSE system("pause")
#define CLS system ("cls")
#define FLUSH flush()
#define MAXELEMENTS 25
#include <stdio.h>
#include <stdlib.h>
// prototyped functions
int pressKeys(char keys);
main() {
char keys[MAXELEMENTS];
int x;
pressKeys(&keys[MAXELEMENTS]);
PAUSE;
}
// functions
int pressKeys(char keys) {
printf("Enter characters: \n");
scanf("%c", &keys); FLUSH;
printf("You typed: %c\n", keys);
return(0);
}
The output of this program seems to be the first character I typed in, so a part of it is working, though it only shows what is in keys[0].
How do I get it to store everything typed?
How do I get printf to output the complete array?
How would I then go about passing the array to the function that will sort the contents in the elements?
(As far as arguments go in both main and the function declaration).
&keys[MAXELEMENTS]is address of last element . (and It doesn't use :-)