Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Created December 31, 2014 09:26
Show Gist options
  • Save arn-ob/7f041c128de55f3876c2 to your computer and use it in GitHub Desktop.
Save arn-ob/7f041c128de55f3876c2 to your computer and use it in GitHub Desktop.
Analyzing a link of text [Not solved]
#include<stdio.h>
#include<ctype.h>
// Function prototype
void scan_line(char line[], int *pv, int *pc, int *pd, int *pw, int *po);
void main(){
char line[80];
int vowels = 0;
int consonants = 0;
int digits = 0;
int whitespc = 0;
int other = 0;
char a;
printf_s("Enter a line of text : \n");
scanf_s("%[^\n]", line);
scan_line(line, &vowels, &consonants, &digits, &whitespc, &other);
printf_s("\nNo of vowels : %d ", vowels);
printf_s("\nNo of consonants : %d ", consonants);
printf_s("\nNo of digits : %d", digits);
printf_s("\nNo of whitespace : %d", whitespc);
printf_s("\nNo of Other Characters : %d", other);
}
void scan_line(char line[], int *pv, int *pc, int *pd, int *pw, int *po){
// analyse the character in a line of text
char c; // uppercase character
int count = 0; // character counter
while ((c=toupper(line[count]))!='\n')
{
if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
{
++ *pv;
}
else if (c>='A'&&c<='Z')
{
++ *pc;
}
else if (c>='0'&&c<='9')
{
++ *pd;
}
else if (c == ' '||c == '\t')
{
++ *pw;
}
else
{
++ *po;
}
++count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment