Like Tree3Likes
  • 1 Post By laserlight
  • 1 Post By Matticus
  • 1 Post By laserlight

lvalue required as increment operand

This is a discussion on lvalue required as increment operand within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main() { char a[]="Hello"; while (*a!='

Like Tree3Likes
  • 1 Post By laserlight
  • 1 Post By Matticus
  • 1 Post By laserlight

Thread: lvalue required as increment operand

') { printf("%c", *a); a++; } return 0; } Why the ...

  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
    21,993
    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.
    justine likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,591
    justine likes this.

  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
    21,993
    What are you trying to do that required something in conio.h?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,993
    Why do you need getch(), putch(), etc?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    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
    21,993
    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.
    AndiPersti likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,993
    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++.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,500
    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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21