How to call the function of C file in .m file for IOS Objective-C? -
in new objective-c project
, create file viewcontroller.m
.
and add other source c file
, header file
in objective-c project
.
if function in c file
following:
int dump(addr) { //function code }
i add button
in viewcontroller.m
following code.
- (ibaction)showclient:(id)sender { //how call function in c file here ? }
how call dump
function in viewcontroller.m
after push button
?.
-----------------------------------edit--------------------------------
the function want call in .m file
/* * dump entire arp table */ int dump(addr) u_long addr; { int mib[6]; size_t needed; char *host, *lim, *buf, *next; struct rt_msghdr *rtm; struct sockaddr_inarp *sin; struct sockaddr_dl *sdl; extern int h_errno; struct hostent *hp; int found_entry = 0;
mib[0] = ctl_net; mib[1] = pf_route; mib[2] = 0; mib[3] = af_inet; mib[4] = net_rt_flags; mib[5] = rtf_llinfo; if (sysctl(mib, 6, null, &needed, null, 0) < 0) err(1, "route-sysctl-estimate"); if ((buf = malloc(needed)) == null) err(1, "malloc"); if (sysctl(mib, 6, buf, &needed, null, 0) < 0) err(1, "actual retrieval of routing table"); lim = buf + needed; (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; sin = (struct sockaddr_inarp *)(rtm + 1); sdl = (struct sockaddr_dl *)(sin + 1); if (addr) { if (addr != sin->sin_addr.s_addr) continue; found_entry = 1; } if (nflag == 0) hp = gethostbyaddr((caddr_t)&(sin->sin_addr), sizeof sin->sin_addr, af_inet); else hp = 0; if (hp) host = hp->h_name; else { host = "?"; if (h_errno == try_again) nflag = 1; } printf("%s (%s) @ ", host, inet_ntoa(sin->sin_addr)); if (sdl->sdl_alen) ether_print((u_char *)lladdr(sdl)); else printf("(incomplete)"); if (rtm->rtm_rmx.rmx_expire == 0) printf(" permanent"); if (sin->sin_other & sin_proxy) printf(" published (proxy only)"); if (rtm->rtm_addrs & rta_netmask) { sin = (struct sockaddr_inarp *) (sdl->sdl_len + (char *)sdl); if (sin->sin_addr.s_addr == 0xffffffff) printf(" published"); if (sin->sin_len != 8) printf("(weird)"); } printf("\n"); } return (found_entry); }
#import "cfile.h"
inviewcontroller.m
- call ordinary c --
function(parameters);
(3. friendly advice: buy book on c)
Comments
Post a Comment