How to access individual characters in an array?

This is a discussion on How to access individual characters in an array? within the C Programming forums, part of the General Programming Boards category; This is my code: Code: char get_bits_squeeze(char num, char mask) { num = print32bits(num); mask = print32bits(mask); char activeBits; for ...

  1. #1
    Registered User
    Join Date
    May 2010
    Location
    San Jose, California, United States
    Posts
    22

    Question How to access individual characters in an array?

    This is my code:
    Code:
    char get_bits_squeeze(char num, char mask)
    {
    	num = print32bits(num);
    	mask = print32bits(mask);
    	char activeBits;
    	for (int i=0;i<32;i++)
    	{	if (mask[i]=='1')
    			strcat(activeBits,num[i]);
    	}
    	return activeBits;
    }
    (num and mask represent 32-char long bit sequences)

    I compile via gcc and I get this error:
    Code:
    error: subscripted value is neither array nor pointer
    error: subscripted value is neither array nor pointer
    referring to mask[i] and num[i], so how do I access the individual char at a given point?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char get_bits_squeeze(char num, char mask)
    That's a single character you've got for an argument, not an array.


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

  3. #3
    printf("Hello Cboard\n"); codeprada's Avatar
    Join Date
    Jan 2011
    Location
    In a little room at the back of your brain
    Posts
    68
    pass this instead
    Code:
    char get_bits_squeeze(char * num, char * mask)
    or
    Code:
    char get_bits_squeeze(char num[], char mask[])

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 07:00 AM
  2. Replies: 13
    Last Post: 09-24-2008, 07:16 PM
  3. copying the first 10 characters to an array?
    By arya6000 in forum C Programming
    Replies: 3
    Last Post: 09-20-2008, 11:39 PM
  4. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  5. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 09:05 AM

Tags for this Thread


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