How can I make the system call write() print to the screen?

前端 未结 5 1448
故里飘歌
故里飘歌 2021-02-01 22:48

For my OS class I\'m supposed to implement Linux\'s cat using only system calls (no printf)

Reading this reference I found it being used to print to a file. I guess I sh

5条回答
  •  感情败类
    2021-02-01 23:39

    #include 
    /* ... */
    const char msg[] = "Hello world";
    write( STDOUT_FILENO, msg, sizeof( msg ) - 1 );
    

    First argument is the file descriptor for STDOUT (usually 1), the second is the buffer to write from, third is the size of the text in the buffer (-1 is to not print zero terminator).

提交回复
热议问题