Solved

tolower( )

Posted on 2004-11-01
382 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
Question by:komlaaa
    8 Comments
     
    LVL 11

    Accepted Solution

    by:
    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
    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 45

    Assisted Solution

    by:Kdo

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

    Can you post your Makefile?

    Kent
    0
     
    LVL 4

    Assisted Solution

    by:bytta
    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
    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 45

    Expert Comment

    by:Kdo

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    875 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now