简体   繁体   中英

How to set objective c label with cons char function in c

I want to run my function TestConnection(const char) and set the value from it for my label in objective c. Any help would be greatly apprecitated I keep getting this error "Incompatible integer to pointer conversion sending 'char' to parameter of type 'const char *_Nonull' in xcode.

Here is my c code

fucn.c

const char TestConnection(const char *ip)
{
    //char ipAddr[] = "133.131.232.131";
    char *val = P(ip);
    char *valb = "0packets";
    if(strcmp(val, valb) == 0)
    {
        printf("%s\n", "noconnection");
        //return "noconneciton";
    }
    else
    {
        printf("%s\n", "connected");
        //return "connected";
    }
    return *val;
}

func.h

#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

const char TestConnection(const char *ip);

objective c code Viewcont.m

- (void)checkconneciton:(NSString*)ip {
    const char *ipc = [ip UTF8String];
    //TestConnection(ipc);

    //below is the line with the error. 
    NSString* xx = [NSString stringWithUTF8String:TestConnection(ipc)];
    _ip_label.stringValue = xx;

}

TestConnection is defined as returning a single character, not a string.

It needs to return a string -- const char * -- which can then be used to initialize the NSString .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM