下面的代码将文件内容读入缓冲区,然后对其进行某些操作。
第9行的
char *getData(){
char *buf = (char*) malloc(100);
//write file contents to buf
return buf;
}
char *bar(char *buf){
//do something with buf
return buf;
}
int main(void){
char *result;
result = bar(getData());
return 0;
}
第9行的
return buf;
可以正常工作 - 它返回整个字符串。问题是如何在函数bar中访问buf中的单个字符?