pointers problem

This is a discussion on pointers problem within the C Programming forums, part of the General Programming Boards category; hi all... learning c pointers. i have this code : PHP Code: #include <stdio.h> int main  ()  {          char string3 [ 10 ],  ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    18

    pointers problem

    hi all...

    learning c pointers. i have this code :
    PHP Code:
    #include <stdio.h>
    int main ()  {
            
    char string3[10], string4[] = "foo moo loo";

            for(; (*
    string3 = *string4) != '\0'string3++,string4++)
                    ;
    return 
    0;

    the compiler returns:

    strings.c: In function `main':
    strings.c:25: error: wrong type argument to increment
    strings.c:25: error: wrong type argument to increment
    strings.c:25: warning: left-hand operand of comma expression has no effect
    strings.c:25: warning: statement with no effect


    what i don't understand is why the "wrong type argument to increment" error?
    if the array name is also a pointer to the first element in the array and i'm using pointer aritmetic to move through the array/string why 'wrong type'?! isn't the address always an int?!

    thanks....

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    You can't increment an array name, it's illegal. The whole "array name is a pointer" is a common misconception. They aren't, in fact, the same thing. Assign the array names to a pointer and increment that.
    Sent from my iPad«

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    18
    Quote Originally Posted by SlyMaelstrom
    You can't increment an array name, it's illegal. The whole "array name is a pointer" is a common misconception. They aren't, in fact, the same thing. Assign the array names to a pointer and increment that.
    thanks...

    i'll use [code] next time... promise...

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Quote Originally Posted by toshog
    i'll use [code] next time... promise...
    Heh... well, at least you used some tags. Most people just paste the code right into the body sans indentation.
    Sent from my iPad«

  5. #5
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    I spot an overflow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with file handling (pointers)
    By hmk in forum C Programming
    Replies: 5
    Last Post: 09-19-2008, 11:03 AM
  2. Problem with pointers
    By kotoko in forum C Programming
    Replies: 3
    Last Post: 06-12-2008, 06:17 AM
  3. A problem with pointers
    By vsla in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 05:14 AM
  4. Returning pointer to array of pointers problem
    By jimzy in forum C Programming
    Replies: 15
    Last Post: 11-11-2006, 06:38 AM
  5. Problem writing swap using pointers
    By joshdick in forum C++ Programming
    Replies: 1
    Last Post: 02-29-2004, 10:06 PM

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