我想运行我的函数TestConnection(const char),并在objective c中为我的标签设置值。任何帮助都会非常感激我不断得到这个错误"不兼容的整数到指针转换发送'char'到xcode中类型'const char *_Nonull'的参数。"
这是我的c代码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("%sn", "noconnection");
//return "noconneciton";
}
else
{
printf("%sn", "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);
目标c代码view .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
被定义为返回单个字符,而不是字符串。
它需要返回一个字符串——const char *
——然后可以用来初始化NSString
。