Write a C program that examines each character in
a two-dimensional array and determines how many
of the characters are vowels (a, e, i, o, u), how
many are consonants, how many are digits and how
many are other kinds of characters. The program
should also determine the number of character “n”
appeared in the text.
The program should read in three lines of text and
store it in a two-dimensional character array.
Assume that array can store up to 80 characters.
Display the results on the screen.
An example of input/output is shown below
Enter three lines of text :
CE1100 Computer Programming
Assignment #10
Question #1
No. of vowels : 14
No. of consonants : 25
No. of digits : 7
No. of other characters : 6
No. of occurrences for letter n : 4
My wrong answer :
#include <stdio.h>
#include <ctype.h>
void main()
{
int v=0,c=0,d=0,o=0,i,j;
char s[3][80];
-gets(s) is wrong I believe. It should be gets(s[i]) and be called in a loop that loops 3 times (and i is the loop counter starting at zero). And that is assuming gets() can read an entire string from keyboard. Personally don't do console apps, and if I do, I use C++'s IO streams (cin, cout, cerr). So we are clear, you are using C functions (gets(), printf(), etc). Any reason why? Is this meant to be C and not C++?
-Your first for loop needs to stop when the null char is reached, yes, but also if you reach the 80th character.
-Your outer for loop is incorrect. You should first loop from 0 to 2 (the string index), and then from o to 80 (exclusive) or null char in a second, inner loop.
There could be other issues but the above should keep you busy. Also use [code]//Code goes here. [/code] tags so code you post is properly formatted and easy to read.