UCHAR array question

This is a discussion on UCHAR array question within the C Programming forums, part of the General Programming Boards category; Hello, I am trying to search a UCHAR array for the word DVD. Code: UCHAR VolumeIdentifier[32]; calc(*VolumeIdentifier); calc function Code: ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    25

    UCHAR array question

    Hello,

    I am trying to search a UCHAR array for the word DVD.

    Code:
    UCHAR  VolumeIdentifier[32];
    
    calc(*VolumeIdentifier);
    calc function
    Code:
    void calc(UCHAR VolumeIdentifier)
     {
           for(int i = 0; i < 30; i++)
            {
                if(VolumeIdentifier[i] == 'D')  
                {
                    if(VolumeIdentifier[i + 1] == 'V')
                    {
                        if(VolumeIdentifier[i + 2] == 'D')
                        {
                            counter++;
                        }
                    }
                    
                }
            }
    }
    The error is on each if statement. Error = invalid types UCHAR[int] for array subscript.

    Does anyone know what would work?


    Many thanks!
    Last edited by Witchfinder; 04-27-2009 at 10:58 AM.

  2. #2
    Registered User
    Join Date
    Apr 2009
    Posts
    7
    Quote Originally Posted by Witchfinder View Post
    Hello,

    I am trying to search a UCHAR array for the word DVD.

    Code:
    UCHAR  VolumeIdentifier[32];

    Code:
            for(int i = 0; i < 30; i++)
            {
                if(VolumeIdentifier[i] == 'D')  
                {
                    if(VolumeIdentifier[i + 1] == 'V')
                    {
                        if(VolumeIdentifier[i + 2] == 'D')
                        {
                            counter++;
                        }
                    }
                    
                }
            }
    The error is on each if statement. Error = invalid types UCHAR[int] for array subscript.

    Does anyone know what would work?


    Many thanks!
    Interesting, UCHAR is defined as typdef unsigned char UCHAR, so the if statements should be fine, you can give this a try.

    if ( temp[i] == (UCHAR)'A')

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Make sure UCHAR is defined within the scope of your program(#ifdef). Also I might recommend using a function like strncmp.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    25
    Quote Originally Posted by sbattu View Post
    Interesting, UCHAR is defined as typdef unsigned char UCHAR, so the if statements should be fine, you can give this a try.

    if ( temp[i] == (UCHAR)'A')
    Unfortunately it doesn't work. Thanks tho.

    I can print VolumeIdentifier so it must be within the scope of the program. I could use strncmp but I still need to go to certain positions within the array, I think.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Obviously the function accepts only one character, not a string of UCHAR, in which case the prototype needs to be:

    Code:
    void calc(const UCHAR* VolumeIdentifier)
    It would probably be sort of nice if this function returned something too.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    25
    Sorted it. The functions going to output data through a GUI.

    Thanks again.

  7. #7
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Quote Originally Posted by Witchfinder View Post
    I could use strncmp but I still need to go to certain positions within the array, I think.
    You could still use strncmp. strncmp takes in a pointer, so as long as your keeping track of what position you are at, you can just add that number to the pointer.

  8. #8
    Registered User
    Join Date
    Apr 2009
    Location
    Russia
    Posts
    116
    counts word in line
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM

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