Confused by this question, C++ and java api version


  • 0
    W

    in C++ version, it seems pretty straightforward what this problem want us to do

    C++ version:

    int read(char *buf, int n) is asking us to read n byte FROM char *buf

    However, when i check the Java version, it is indicating otherwise,

    Java version

    public int read(char[] buf, int n) requires us to read n char TO char[] buf, like this java solution indicates

    Am I getting it right?


  • 0
    S

    "int read(char *buf, int n) is asking us to read n byte FROM char *buf"

    Not really. Just like the Java API, you need to read n bytes (from a file) TO char *buf. You don't need to worry about which file to read these bytes from, because read4 knows all the low-level details of reading.


  • 0

    buf is clearly documented as "Destination buffer"

    Also, how would reading from the buffer even make any sense?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.