473,480 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

calling function for each time for each word? duplicate?

254 Contributor
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <map>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8.  
  9. void f(string str){
  10.     transform(str.begin(), str.end(), str.begin(), ptr_fun(::tolower));
  11. }
  12.  
  13. void testFunc(){
  14.     map<string, int> frequent;
  15.     string str;
  16.        string strr;
  17.  
  18.     while(cin >> str){
  19.         strr = f(str);       // keep calling f(str) function in order to convert to lowercase.
  20.         frequent[str]++;
  21.     }
  22.     map<string, int>::const_iterator it;
  23.         for (it=frequent.begin(); it != frequent.end(); ++it) {
  24.         cout << it->second << " " << it->first << endl;
  25.     }
  26. }
  27.  
  28. int main(int argc, char* argv[]){
  29.  
  30.     string str2;
  31.     ifstream myfile;
  32.  
  33.     switch(argc){
  34.     case 1:      // no filename specified
  35.  
  36.         testFunc();
  37.         break;
  38.  
  39.     case 2:      // filename specified
  40.  
  41.         myfile.open(argv[1], ios::in);         // open the report.txt
  42.         if(myfile.is_open()){
  43.             while(! myfile.eof()){
  44.                 getline(myfile,str2);
  45.             }
  46.         }
  47.         else{
  48.             //cout << "Unable to open the file" << endl;
  49.         }
  50.         break;
  51.     }
  52.     return 0;
  53. }
  54.  
My code above, okay or not?
Is there any other simple way to convert all words user type in to lowercase by just calling the function ONCE only ?
look at the while loop in the function testFunc() ....
(try run the above program using NO command line argument, thanks)

thanks in advance.
Nicky Eng.
Nov 22 '06 #1
0 1022

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

Similar topics

13
6324
by: Nige | last post by:
To save me re-inventing the wheel, does anyone have a function to capitalise each word in form data? I was thinking along the lines of capitalise the first letter of the string, then any other...
1
2299
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
4
1719
by: Gibby Koldenhof | last post by:
Hiya, I'm setting up some code in the spirit of Design Patterns, OOP, etc. All nice and well, it handles pretty much all OO style things and serves my purposes well. There's one last final...
19
4216
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
3
2378
by: Scupper | last post by:
I am working on adapting a process currently handled by VBA functions in a Word template, moving to a VB.NET app that calls Word only when necessary to manipulate documents (essentially, it is...
8
3808
by: Noozer | last post by:
I'm looking for a way to generate a "clone" of an object. Right now I need to write a Clone function for every class that make and I'd like to have a generic routine. Instead of doing this: For...
4
1364
by: Peter Afonin | last post by:
Hello, I have a weirdest issue I've ever had. I have a function that enters some data into the Oracle table and returns the sequential row number for the new record (autonumber): Private...
10
6920
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
2267
by: saijin | last post by:
I'm planning to call a list of data from an XML file but when I duplicate the content inside the <data></data> it is not showing anything Here's the ActionScript 3.0 import...
0
7039
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
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7080
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...
0
6895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.