How can I fix up these C Problem? I need to read three lines

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





#include <stdio.h>

#include <ctype.h>

#include <string.h>

void main ()

{

char string[4][20];

int a=0,b=0,c=0,d=0,j=0,i=0;

puts("input");

gets("string");

for(j=0;string[i][j]!=0;j++)

{

if(isdigit(string[i][j])!=0)

{

a++;

}

if(isalnum(string[i][j])!=0)


{
if(isupper(string[i][j])=='A'|| isupper(string[i][j])=='U'|| isupper(string[i][j])=='E'|| isupper(string[i][j])=='I'|| isupper(string[i][j])=='U')
{

b++;

}

else

{

c++;

}

}

else if(isalnum(string[i][j])==0)

{

d++;

}

j++;

}

printf("vowels : %c",b);

printf("consonant : %c",c);

printf("digit : %c",a);

printf("other : %c",d);

printf("occurrences for letter n : 4");
}
sounds like homework ;-)
I dont see an i++ in there.
closed account (1vRz3TCk)
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
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define LINES 3
#define CHARACTERS 80

int main (void)
{
    char lines[LINES][CHARACTERS + 1];
    int line_number = 0;
    int char_number = 0;
    int vowel_count = 0;
    int consonant_count = 0;
    int digit_count = 0;
    int other_count = 0;
    int n_count = 0;

    printf("Enter three lines of text : \n");
    for(line_number = 0; line_number < LINES; ++line_number)
    {
        fgets(&lines[line_number][0], CHARACTERS, stdin);
    }

    for(line_number = 0; line_number < LINES; ++line_number)
    {
        for(char_number = 0; char_number < CHARACTERS; ++char_number)
        {
            char c = lines[line_number][char_number];
            if (c == '\0' || c =='\n') break;

            if (isdigit(c)) digit_count++;
           
            /* and so on */
        }
    }

    printf("No. of digits : %i\n", digit_count);

    return 0;
}
NB: untested but should compile.
Last edited on
I have done it already by myself! But still one thing left! I have to count how many "n" are here! Can anybody help plzzzzz?

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50


#include<stdio.h>
#include<ctype.h>

void main()
{
	int i, j,  vowel=0, con=0, digit=0, other=0;
	char s[3][80];
	printf ("Enter three lines of text :\n");
	for (i=0;i<=2;i++)
	{
		gets (s[i]);
	}
	for (i=0;i<=2;i++)
	{
		for (j=0;s[i][j]!='\0';j++)
		{
			if (isalpha (s[i][j])!=0)
		{
			if (tolower (s[i][j])=='a'|| tolower (s[i][j])=='e'|| tolower (s[i][j])=='i' || tolower (s[i][j])=='o' || tolower (s[i][j])=='u')
			{
				vowel++;
			}
			else
			{
				con++;
			}
		}
		else if (isdigit (s[i][j]) !=0)
		{
			digit++;
		}
		else if (isalnum (s[i][j]) ==0)
		{
			other++;
		}
		}
		
	}
		printf ("Number of consonants are %d\n", con);
		printf ("Number of vowels are     %d\n", vowel);
		printf ("Number of digits are     %d\n", digit);
		printf ("Number of others are     %d\n", other);
}




Topic archived. No new replies allowed.