先新建一个c文件和头文件,写个简单的printf方法
WTTestC.h
#ifndef WTTestC_h
#define WTTestC_h
#include <stdio.h>
void printfHelloWord(void);
#endif /* WTTestC_h */
WTTestC.c
#include "WTTestC.h"
void printfHelloWord(void)
{
printf("hello world!");
}
再新建一个OC的Viewcontroller用来调用上面C文件的方法
.m中
#import "WTRootViewController.h"
#include "WTTestC.h"
@interface WTRootViewController ()
@end
@implementation WTRootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
printfHelloWord(); //此即为上面C文件的方法
@end
ok,运行即可在打印信息处看到打印结果hello world!,方法调用成功
网友评论