Program that counts letter and space occurences from user input

Firstly I need to prompt the user to enter a sentence that contains between 10 to 20 words and it is supposed to give the user the number of times each letter and space in his/her sentence occurs .
And secondly, I'm not sure how to write such a program, i don't even know where to start so it would be helpful if someone could write out a very simple sample program that performed it. I would be really grateful. Thank You.

Step 1:
I need to prompt the user to enter a sentence

Step 2: Read the input
Step 3:
supposed to give the user the number of times each letter and space in his/her sentence occurs
In other words, count each occurrence of each distinct character in their sentence. Summing(counting) each one distinctly.
Step 4: Output the results.

i don't even know where to start

Begin with step one.
Last edited on
Here is what i have so far though its not working still :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <ctype.h>
#define SIZE 20

int main(void)
{
	char sentence[SIZE];
	int i;
	int Alphabet[26];
	int count = 0;

	char Alphabet[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','r','s','t','u','v','w','x','y','z','\0'};

	printf("Enter a line of text: ");
	if (fgets(sentence, sizeof sentence, stdin)){
		printf(sentence);
	}
	for(i=0; sentence[i] != '\0'; i++){
		sentence[i] = tolower(sentence[i]);
	}
	printf(sentence);
	getchar();

	for (i=0; i<=26; ++i){
		if (Alphabet[i]==sentence[i]){
			count++;
		}
	}

	return count;
	
}

and this is what the error says:

1>------ Build started: Project: Project 5, Configuration: Debug Win32 ------
1>  Project_5.c
1>c:\users\howard\documents\visual studio 2010\projects\project 5\project 5\project_5.c(12): error C2371: 'Alphabet' : redefinition; different basic types
1>          c:\users\howard\documents\visual studio 2010\projects\project 5\project 5\project_5.c(9) : see declaration of 'Alphabet'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



pleease somebody help me!
Last edited on
You have two variables of the same name with different basic types (int / char)
int Alphabet[26];

char Alphabet[]
Topic archived. No new replies allowed.