Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

tolower( )

Posted on 2004-11-01
8
Medium Priority
?
385 Views
Last Modified: 2011-09-20
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
Comment
Question by:komlaaa
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 400 total points
ID: 12464297
tolower('A') returns 'a' - it does not change the value in-place...

you should do something like:

s[i] = tolower(s[i]);
0
 

Author Comment

by:komlaaa
ID: 12465499
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
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 200 total points
ID: 12465675

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

Can you post your Makefile?

Kent
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 4

Assisted Solution

by:bytta
bytta earned 200 total points
ID: 12466383
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
 

Author Comment

by:komlaaa
ID: 12468051
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12468146

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
 
LVL 4

Expert Comment

by:bytta
ID: 12471909
"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
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12471962
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question