pointers to strings

write a program to count numbers of "e" in the following array of pointers to strings:

char*s[]={"we will teach you hoe to....."
"move a mountain'"
"level a building"/
}



help me out im new to it
You could try doing a for loop until you find an 'e' in the array, then increment a counter. It could be time consuming however.
can u please send me the code i tried using loop but didnt got success in that its not my assignment but im learning some techniques of C++.help me in this regard.
I hope this code helps you to understand techniques of c/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()
{
	char* s[]={"we will teach you hoe to.....","move a mountain'","level a building","ill teach yo"};
	int size = sizeof(s)/sizeof(char*);                                                                          
	int count = 0;

	printf("Size of Array : %d\n",size);

	for (int i = 0; i < size; i++)
	{
		char * pch;
		printf ("Looking for the 'e' character in \"%s\"...\n",s[i]);
		pch=strchr(s[i],'e');
		while (pch!=NULL)
		{
			printf ("found at %d\n",pch-s[i]+1);
			count++;
			pch=strchr(pch+1,'e');
		}
	}


	printf("Count of 'e' : %d\n",count);                                          

	getchar();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.