?
Solved

void star to char star star

Posted on 2005-05-02
3
Medium Priority
?
1,537 Views
Last Modified: 2008-01-09
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
Comment
Question by:arabiafish
  • 2
3 Comments
 
LVL 6

Expert Comment

by:vadim_ti
ID: 13913897
static int test(const void *s, int numBuckets)  
{            
    int i, num;
    char *ss;

    ss = s;
    while (*ss++)
       num += tolower(*s + i);  
    return num                        
}
0
 

Author Comment

by:arabiafish
ID: 13913941
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
 
LVL 6

Accepted Solution

by:
vadim_ti earned 2000 total points
ID: 13913953
static int test(const void *s, int numBuckets)  
{            
    int i, num;

    while (*((char*)s)++)
       num += tolower(*((char*)s) + i);  
    return num                        
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question