-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex3-1.c
31 lines (30 loc) · 902 Bytes
/
ex3-1.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
int i,lettersNum[26]={0};
char *words[20];
printf("Insert 20 words. Press Enter after every word you enter.\n");
for(i=0;i<20;i++){
char temp[50];
char *tmp=temp;
printf("%2d: ",i+1);
scanf("%s",temp);
words[i] = malloc(strlen(temp)*sizeof(char)+1);
strcpy(words[i],tmp);
int j=0;
while(*(tmp+j)!='\0'){
if(*(tmp+j)>=65 && *(tmp+j)<=90){lettersNum[(*(tmp+j)-65)]++;}
if(*(tmp+j)>=97 && *(tmp+j)<=122){lettersNum[(*(tmp+j)-97)]++;}
j++;
}
free(words[i]);
}
for(i=0;i<26;i++){
printf("\n[%c]: ",i+65);
int j;
for(j=0;j<(lettersNum[i]/10);j++){printf("*");}
for(j=0;j<(lettersNum[i]%10);j++){printf("-");}
}
return 0;
}