Thread: lvalue required as increment operand

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    41

    lvalue required as increment operand

    Code:
    #include <stdio.h>
    int main()
    {
        char a[]="Hello";
        while (*a!='\0')
        {
             printf("%c", *a);
             a++;
        }
        return 0;
    }
    Why the error ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    a is an array, hence it cannot be modified in itself. You should create a pointer to char to point to the first character of a.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    41
    Thank you.
    PS:In gcc no conio.h, what is the alternative?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What are you trying to do that required something in conio.h?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    41
    getch(), putch(), etc

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Why do you need getch(), putch(), etc?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Use getchar() and putchar() respectevily.

  9. #9
    Registered User
    Join Date
    Nov 2012
    Posts
    41
    laserlight
    For doing exercise in my book.
    qny
    aware of that, qny

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by justine
    For doing exercise in my book.
    In that case, just substitute with the standard library near-equivalents. They certainly don't do the exact same thing, but for the purposes of learning, they will be as adequate. This way, your code will be more portable, what you learn will have somewhat greater applicability, and if you post your code here, people will more likely be able to quickly get up to speed with it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Nov 2012
    Posts
    41
    I was checking the action of each function:
    Code:
    #include <stdio.h>
    using namespace stdin;
    int main()
    {
        char ch;
        printf("Press ant key to continue\n");
        getch();
        printf("Press ant key to continue\n");
        ch=getche();
        printf("Press ant key to continue\n");
        getchar();
        printf("Continue Y/N");
        fgetchar();
        return 0;
    }
    I heard about "using namespace std" something like that?

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, do you really need this "press any key to continue" feature?

    Quote Originally Posted by justine
    I heard about "using namespace std" something like that?
    That is C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    If you can't test the functions, you can read about them and work out what they are supposed to do.

    The MSDN site is probably best for that

    But whilst reading them, remember that in this day and age they are very uncommon.
    Fact - Beethoven wrote his first symphony in C

  14. #14
    Registered User
    Join Date
    Nov 2012
    Posts
    41
    Okey.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lvalue required as left operand of assignment
    By Thai guy in forum C Programming
    Replies: 4
    Last Post: 06-03-2012, 07:58 PM
  2. lvalue required as left operand of assignment
    By ModeSix in forum C Programming
    Replies: 6
    Last Post: 04-14-2011, 12:45 PM
  3. fixing lvalue quired as increment operand
    By candy.chiu.ad in forum C Programming
    Replies: 9
    Last Post: 03-07-2011, 02:56 PM
  4. Lvalue required as increment operand
    By .C-Man. in forum C Programming
    Replies: 4
    Last Post: 10-13-2010, 02:41 PM
  5. lvalue required as increment operand compile error
    By canadatom in forum C Programming
    Replies: 8
    Last Post: 06-13-2009, 11:49 AM