• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1572
  • Last Modified:

void star to char star star

Can someone explain when and why a void star needs to be converted to a char star star? The actual parameter s is a char *, and the formal parameter s is (obviously) a void *. However, I seem to remember that the void star needs to be a char star star, because it's a string that's being passed in. Here's an example of what I'm doing (I don't know if it's correct)

static int test(const void *s, int numBuckets)  
{            
    int i, num;

    for (i = 0; i < strlen((char *)(char *)s); i++)  
      num = num + tolower((char *)s + i);  

    return num                        
}

Is this correct? void *s is being passed a string.
0
arabiafish
Asked:
arabiafish
  • 2
1 Solution
 
vadim_tiCommented:
static int test(const void *s, int numBuckets)  
{            
    int i, num;
    char *ss;

    ss = s;
    while (*ss++)
       num += tolower(*s + i);  
    return num                        
}
0
 
arabiafishAuthor Commented:
Thanks! What if I didn't want to declare char *ss-- how would I write the conversion if I wanted to put it inline with the code itself?
0
 
vadim_tiCommented:
static int test(const void *s, int numBuckets)  
{            
    int i, num;

    while (*((char*)s)++)
       num += tolower(*((char*)s) + i);  
    return num                        
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now