1

I need to use a returned value of a C function in objective C..for Ex:consider a file samplec.h & samplec.c..It contains method definition for display i.e..

char *display()
{
    char *b="Hi";
    printf("%s",b);
    return b; 
}

This returned value should be called and used in objective C function i.e..in sampleObjC.m which exist in same project. Can anybody help me with an idea how to do this or any alternatives if exist for passing string value from c file to objective c file in a same project?

1 Answer 1

3
// sampleObjC.m
#include sampleC.h

- (void)myMethod {
    NSString *string = [NSString stringWithUTF8String:display()];
    NSLog(@"%@", string); 
}
Sign up to request clarification or add additional context in comments.

5 Comments

Hi Eimantas..Thanks a lot for help..I got what I was trying for :)
Hi Eimantas ..how can I pass this ... void hseInitialize(void (*receiveCallback)(char *data)); to viewcontroller.m file by using NSString *string = [NSString stringWithUTF8String:hseInitialize......].
wat arguments should I give ??
You can't pass that function call since function returns void. Not sure what you are trying to achieve here.
Ok..Any other method to pass one function & its arguments to another function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.