• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

tolower( )

Below is how i am using to lower built in method to conver a word to lower cases. But for some reason, it is not working. Why?

================================= CODE ===============================
//convert a string to lower case
std::string toLower(std::string & s){
for(unsigned int i = 0; i < s.length(); i++)
  tolower(s[i]);
 return s;
}

//read the file word per word, remove punctuation if any,
//store them into vector words. Duplicates not allowed.
void wc::read(istream &f)
{
   std::string word;
   int count = 0;

    f.seekg(0, ios::beg);
   f >> word;

     while(!f.eof()){
    removePunc(word);
if(passWordTest(word)){
   word =  toLower(word);
  if( words.find(word) == words.end()  )
   words[word] = 0; //word is not in map set it count to 0 for the first time.

 words[word]++; //word is there, increment its count.
 count++; //count the number of word stored.

}
 f >> word;
}
  if(words.size() == 0){
  std::cout<<"File failed to open\n";
  exit(0);
}
  totalCount = count;
  distinctCount = words.size();
}


Thanks

0
komlaaa
Asked:
komlaaa
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
cjjcliffordCommented:
tolower('A') returns 'a' - it does not change the value in-place...

you should do something like:

s[i] = tolower(s[i]);
0
 
komlaaaAuthor Commented:
What does the error message below mean?

crux:~/cs450/a2> ls
BUG_LOG     Makefile*   TIME_LOG    main.o      wc.cpp      wc.h
MANPAGE     README      main.cpp    non_words   wc.cpp~     wc.o
crux:~/cs450/a2> make
g++ main.o wc.o -o wc.out
make: execvp: g++: Permission denied
make: *** [wc.out] Error 127
crux:~/cs450/a2>
0
 
Kent OlsenData Warehouse Architect / DBACommented:

gcc (specifically, your user ID) doesn't have permission to access a file.

Can you post your Makefile?

Kent
0
Managing Security & Risk at the Speed of Business

Gartner Research VP, Neil McDonald & AlgoSec CTO, Prof. Avishai Wool, discuss the business-driven approach to automated security policy management, its benefits and how to align security policy management with business processes to address today's security challenges.

 
byttaCommented:
Looks like you don't have permission to run g++

Check if you're allowed to compile on this computer, that is run the following command:
g++ main.o wc.o -o wc.out

if you get "g++: permission denied" the root/admin must fix it for you...
0
 
komlaaaAuthor Commented:
Here is some info

crux:~/achille/a4_1> ls
BUG_LOG*     Makefile*    README*      bible.txt*   f.out*       file1*       main.cpp*    main1.cpp*   test.out*    wc.h*
MANPAGE*     Makefile_1*  TIME_LOG*    error*       file*        getopt.c*    main.cppn*   main_1.cpp*  wc.cpp*
crux:~/achille/a4_1> uname -rs
SunOS 5.8
crux:~/achille/a4_1> cat Makefile

all: cs450words

cs450words:  wc.o main.o getopt.o
        g++ main.o wc.o getopt.o -o cs450words

wc.o: wc.cpp wc.h
        g++ -g -Wall -ansi -c wc.cpp

main.o: main.cpp
        g++ -g -Wall -ansi -c main.cpp

getop.o: getopt.c
        cc -c getopt.c

clean:
        /bin/rm -f cs450words main.o wc.o getopt.o *~

crux:~/achille/a4_1> make
g++ -g -Wall -ansi -c wc.cpp
make: execvp: g++: Permission denied
make: *** [wc.o] Error 127
crux:~/achille/a4_1>
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Yep.  Do an "ls -l " on the directory where gcc lives.

I don't recall which directory is appropriate.  "find / -name g++" should tell you.


Kent
0
 
byttaCommented:
"find / -name g++" should gives you every program with "g++" in the name and takes forever to run on an big HDD

"which g++" gives you the program and takes milliseconds
0
 
cjjcliffordCommented:
this (getting g++ to work) is all off topic from the original question - a seperate question should really have been opened...


However...

find / -type f -name 'g++'
will take some time, but not forever...

If the system is a Linux system there should be "locate" installed:

locate g++

Locate is much faster than "find" as a database of applications should be maintained, and "locate" then just searches through this database...

On my linux server here gcc/g++ are in /usr/bin
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now