• C

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++)
 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;

   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";
  totalCount = count;
  distinctCount = words.size();


Who is Participating?
tolower('A') returns 'a' - it does not change the value in-place...

you should do something like:

s[i] = tolower(s[i]);
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
Kent OlsenData Warehouse Architect / DBACommented:

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

Can you post your Makefile?

Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

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...
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

        /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
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.

"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
this (getting g++ to work) is all off topic from the original question - a seperate question should really have been opened...


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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.