Menu

cin.get(c)

2002-08-29
2012-09-26
  • Nobody/Anonymous

    Hello, my name is Franjo and I have a little problem using Dev-C++. Some programs don't work. For example:

    #include <iostream.h>
    #include <stdlib.h>
    #include <cstring>
    using namespace std;
    int main()
    {
    char* c;
    while(cin.get(c))
    {
    if(c >= 'a' && c <= 'z')c+='A'-'a';//capitalize c
    cout.put(c);
    if(c=='\n')break;
    }
          system("PAUSE");
          return 0;
    }

    After compiling, I get a whole bunch of errors. Do you know what's wrong? Greetings, Franjo

     
    • Nobody/Anonymous

      Wow, I found something!!!!  Woohooo!
      You need to change

      char* c

      to

      char c

      This gets rid of your compile errors.  Now, I don't think the code is working right for you.  For me to input a character into the stream, I have to hit return, which seems to trip your exit logic.

      I think you need to rethink that part of the design.
      I am too fried, and I hate characters, and I am not the sharpest knife in this drawer anyway.

      Wayne

       
    • Curtis Sutter

      Curtis Sutter - 2002-08-30

      #include <iostream.h>
      #include <stdlib.h>
      #include <cstring>
      #include <conio.h>

      using namespace std;

      int main()
      {
        char c;
        while(true)
        {
          c = getch();

          if(c >= 'a' && c <= 'z')
          {
            c+='A'-'a';//capitalize c
            cout.put(c);
          }
          else //if c != any known letter a-z
            break;
        }
        system("PAUSE");
        return 0;
      }

      This works for me, but I do not know what you are trying to do.  To capitalize though, I would include ctype.h and use the toupper command.

      eg:
           c = toupper(c);
           cout.put(c) //instead of      if(c >= 'a' && c <= 'z')
                                                 {
                                                   c+='A'-'a';//capitalize c
                                                   cout.put(c);
                                                 }

      Have fun.

      Curtis

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.