Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,930 members, 7,817,721 topics. Date: Saturday, 04 May 2024 at 05:54 PM

I Have A Few Questions For C Progamming - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Have A Few Questions For C Progamming (755 Views)

Can I Be A Guru In Go Progamming Without Knowledge In C++ Or Python / Hope For C++ Newbies: Gui Toolkits / Few Questions About Aptech Computer Institute??? (2) (3) (4)

(1) (Reply)

I Have A Few Questions For C Progamming by ecrazed: 3:55pm On Mar 29, 2010
1)Write a function CountNumberOfOccurrence which take a string with maximum size of 49
characters (char array size is 50) and returns the number of occurrence of English characters,
spaces, digits and other characters. The number of occurrence for English characters, digits, and
other characters using call by reference and the return value gives the number of occurrence for
spaces. In your main program, you ask the user to input a string, call CountNumberofOccurrence
function to get the corresponding number of occurrence of English characters, spaces, digits and
other characters and display the results. A sample input/output looks like following:
Input:
Enter a string: 8djfa -99jdfadf 882 adf *
Output:
Number of English characters = 13
Number of space = 3
Number of digits = 6
Number of other characters = 2
Re: I Have A Few Questions For C Progamming by sayhi2ay(m): 3:57pm On Mar 29, 2010
so, whats your question ?
Re: I Have A Few Questions For C Progamming by chukxy: 9:12am On Mar 30, 2010
@ poster this might help you.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

void Count_Number_of_occurrence(int *Engchar1,int *space1,int *digit1, int *other1);
void print_result(int *Engchar2,int *space2,int *digit2, int *other2);
int main()
{
int Engchar,space,digit,other;


Count_Number_of_occurrence(&Engchar,&space,&digit,&other);
print_result(&Engchar,&space,&digit,&other);


_getche();
return 0;
}
void Count_Number_of_occurrence(int *Engchar1,int *space1,int *digit1, int *other1)
{
int Eng,spac,dig,oth;
Eng=0;
spac=0;
dig=0;
oth=0;
char ch;
int loop=0;
printf("\n Please enter a statement \n"wink;
while(((ch=(char) getche())!='\0')&&(loop<50))
{
if(ch==' ')
spac++;
else if(ch>='0'&&ch<='9')
dig++;
else if(((ch>='a')&&(ch<='z'))||((ch>='A')&&(ch<='Z')))
Eng++;
else
oth++;

loop++;
}
*Engchar1=Eng;
*space1=spac;
*digit1=dig;
*other1=oth;
}

void print_result(int *Engchar2,int *space2,int *digit2, int *other2)
{
printf("\n Number of English Characters = %d\n",*Engchar2);
printf("\n Number of Space = %d\n",*space2);
printf("\n Number of digits = %d\n",*digit2);
printf("\n Number of other characters = %d\n",*other2);
}

(1) (Reply)

Online Auction Systems / Iis Configuration Problem / How To Download Attached Files In Outlook Messages Automatically Through Java Co

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.