C结构体
谁能给我提供一个最简单的结构体demo,我在做android调用C,需要测试下,但是自己对C不熟,现存的C库还运行不起来。
谁给我写一个头文件,一个c文件,头文件里写一个结构体,结构体三个属性,一个char,一个int,一个char*吧,然后C里写一个函数返回这个结构体。
代码贴完整最好。我要拷贝了拿来直接能用,要C语言的。
[解决办法]
不知道你说的是什么 . 你要的是这种?
.h文件
struct demo
{
char ch;
int data;
char *p;
};
typedef struct demo *pdemo;
.c文件
#include<stdio.h>
#include<stdlib.h>
#include"demo.h"
pdemo func_demo()
{
pdemo test;
test = (pdemo)malloc(sizeof(struct demo));
test->ch = 'a';
test->data = 1;
test->p = NULL;
return test;
}
int main()
{
pdemo temp;
temp = func_demo();
printf("%c %d %x",temp->ch,temp->data,temp->p);
return 0;
}