I have some problems with a pointer. My idea was to pass a buffer to a function in order to store the return data in this buffer. But, I do not know if it will work.
void main()
{
char *buf = malloc(sizeof(char) *buf);
memset(buf, 0x00, BUF_SIZE);
sendCommand(buf);
}
sendCommand(char *buf)
{
write(fd, "some commands", strlen("some commands"));
readResponse(buf);
}
readResponse(char *buf)
{
read(fd, buf, nbytes);
}
I know there is no error handling up to now. And some variables are not well defined. It just depends on the passing buffer. Will I see the data that I get in readResponse() in my main function?
int main(void); you are not free to declare main as you please.memset(buf, 0x00, BUF_SIZE);, you needchar *buf = malloc(BUF_SIZE);. Your expressionsizeof(char) *bufdoesn't make sense. Did you meanBUF_SIZE * sizeof(*buf)?sendCommandshould either just send the command, not get the response, or you change the name to something more appropriate.scanf()works, for example. And so, too, the very sameread()function you are using, for that matter.