C指针void*缓冲区问题

sai*_*dhu 0 c pointers system-calls

很抱歉用C语言搞乱你们.write()采用void*buff.我需要通过提供所需的数据从main()调用此函数.

但是当我打印它时会抛出错误.帮帮我朋友.代码如下.

void write(int fd, void *buff,int no_of_pages)
{
  // some code that writes buff into a file using system calls
}
Run Code Online (Sandbox Code Playgroud)

现在我需要发送buff我需要的数据.

#include "stdio.h"
#include "malloc.h"
int main()
{
int *x=(int*)malloc(1024);
*(x+2)=3192;

*(x+3)="sindhu";

     printf("\n%d %s",*(x+2),*(x+3));      

     write(2,x,10); //(10=4bytes for int + 6 bytes for char "sindhu");
}
Run Code Online (Sandbox Code Playgroud)

它警告我

warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
Run Code Online (Sandbox Code Playgroud)

我该如何删除此警告

bit*_*ask 5

通过强制转换为有效类型:

printf("\n%d %s",*(x+2),(char*)(x+3)); 
Run Code Online (Sandbox Code Playgroud)

注意:你正在做的事情看起来很邪恶.我会重新考虑这个设计!