473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to implement this ?

what is the code to implement this function?
countCharInText
Counts the frequency of a character in a text
the prototype is
int countCharInText(char* text, int size, char toCount);
Dec 3 '08 #1
8 1578
boxfish
469 Expert 256MB
Loop through alll the characters in text and check whether each one is equal to toCount. We can't give you the code for it because you're supposed to do the assignment.
Hope this helps.
Dec 3 '08 #2
this not an assignement I am looking for the code because I need to review for my test and I am not able to impelment the function..so please if you can help me a bit more....
Dec 3 '08 #3
boxfish
469 Expert 256MB
Okay, here's pseudocode:
Expand|Select|Wrap|Line Numbers
  1. Set a counter variable to zero.
  2. For each character in text:
  3.     If it's equal to toCount:
  4.         Increment the counter variable.
  5. Return the counter variable.
I hope this is more helpful. :-)
Dec 3 '08 #4
but there is a problem , for the space and new lignes what should I do?
Dec 3 '08 #5
donbock
2,426 Expert 2GB
@madeofdata
What makes you think there's anything special about space and new line characters? Either the next character in the string matches or it doesn't.

I suggest you post a source code snippet that steps through each character in the string (the 'for' loop in boxfish's pseudocode). No need to do anything in the loop right now. Based on your questions in this thread and in your myStrCmp thread I think you might be having trouble with this task.
Dec 4 '08 #6
this is my function :
int countCharInText(char* text, int size, char toCoun){
char c = 0;
int i = 0;
int frequence = 0;

for(i = 0; i < size-1; i++)
{
if(text[i] == toCount)
frequence++;
}
return frequence;
}

is it correct ?
+ how the main function should be knowing that I cannot use a scanf and that the sentinel is a "."(a dot)
Dec 4 '08 #7
boxfish
469 Expert 256MB
@madeofdata
It would be helpful if you used code tags around your code. Put [CODE] before the code and [/CODE] after it, so it shows up in a code box and the indentation isn't wrecked. Thanks. Anyway, yes, that function looks right, except for that you don't need to declare c, and the condition for your for loop seems to skip the last letter. I'm not sure about the main function; maybe someone else who knows more about c i/o can help with that.
Good luck on your exam.
Dec 4 '08 #8
donbock
2,426 Expert 2GB
@madeofdata
If your input text is a null-terminated string then you don't need to pass in the size -- keep comparing until you find the null character ('\0').
Dec 4 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Charles Law | last post by:
This is going to seem like a basic OO question, but it comes up and bites me every now and again. Suppose we have a multi-tiered protocol to implement, what is the logical, OO way to design the...
2
by: Billy Porter | last post by:
Greetings, I got a class that wraps the System.Data.SqlClient.SqlConnection class (no COM interaction). I'm not sure if I'm supposed to implement the IDisposable pattern for this wrapper or not....
4
by: Sanjay Vyas | last post by:
Sorry, forgot to cross post this one.. This is rather unusual as we would expect any Collection class to implement ICollection interface and furthermore a Dictionary class should implement...
4
by: Peter | last post by:
I want to copy a parent class instance's all datas to a child's. It's actually a C++'s copy constructor. But why the following code does not work - there is a compile error! How it should look...
13
by: Sherif ElMetainy | last post by:
Hello I was just got VS 2005 preview, and was trying generics. I tried the following code int intArray = new int; IList<int> intList = (IList<int>) intArray; it didn't compile, also the...
3
by: Brett Hall | last post by:
I have a VB.NET interface that my managed C++ code is to implement. I seem to be stuck implementing an event defined in that interface. Does anyone have a simple code snippet that will show me...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
7
by: moondaddy | last post by:
If I'm in a class that inherits an interface, is there a shortcut key that will write the implementation of the interface into the class? I remember seeing something like this in vb.net. ...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
5
by: Tony Johansson | last post by:
Hello! Assume you have the following interface and classes shown below. It is said that a class must implement all the methods in the interface it inherits. Below we have class MyDerivedClass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.