Pointer question

This is a discussion on Pointer question within the C Programming forums, part of the General Programming Boards category; Hey guys first post here, I'll try to follow the forum standards. So here is the thing, I'm in to ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Question Pointer question

    Hey guys first post here, I'll try to follow the forum standards.

    So here is the thing, I'm in to PLC programming and as part of the whole deal I have to get familiar with C which is mainly used to create a more advanced and custom interface for HMI programs.

    While poking around some code I got stuck at this part here highlighted.

    Code:
    #include "apdefap.h"
    void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
    {
    #pragma code ("UseAdmin.DLL")
    #include "pwrt_api.h"
    #pragma code ()
    int i, j, n;
    char pic_name[256];
    char obj_name[60];
    PWRTLogout();
    n = strlen( lpszPictureName );
    for ( i = n; i > 0; i-- )
      if ( lpszPictureName[i] == '.' )
        {
        strncpy( pic_name, lpszPictureName, i );
        strcpy( obj_name, &lpszPictureName[i+1] );
        for ( j = 0; j < (n-i); j++)
          if ( obj_name[j] == ':' )
            {
            obj_name[j] = '\0';
            break;
            }
        SetVisible(pic_name,obj_name,FALSE);
        }
    
    }
    don't worry about the header and those wierd names in it, I woud just like to know the part where it says &lpszPictureName[i+] I looked everywhere on the internet and I could not find a single thing about this wierd code (at least for me it is) it seems like a mix of pointers with pointers?

    I got at least the purpuse of the code by looking at it, this code is used to call pictures (HMI screens for industrial process control) and those pictures have .PDL extention so it would extract the NameOfThePicture without the .PDL extention I think and the last part would set it to Invisible ( highlighted in blue).

    Last but not least, I thank you all in advance.
    Last edited by blukrr; 03-17-2011 at 06:28 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can use pointers like arrays, assuming the pointer points to a block of consecutive items:
    Code:
    char array[ FOO ];
    ...
    bar( foo );
    ...
    void bar( char *p )
    {
        p[ 2 ] = 4;
    }
    You can also use the & to get the address you need for a particular item in the array. That's what they are doing. They could have just done:
    Code:
    strcpy( obj_name, lpszPictureName + i + 1 );

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Oh ty!

    gotta be honest I gotta get a lot more familiar with all of this, but I used once the last example you gave and I didn't know the [i +1] and the "i+1"where the same think when pointing.

    cheers!

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    foo[X] is the same thing as *(foo + X)
    &foo[X] is the same as doing foo + X


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 09:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 10:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 01:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

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