简体   繁体   中英

C open() sycall returns -1 for a variable path parameter

Trying to open a file using open(). Returns the correct file descriptor when we call it like so:

fd = open("a.txt", O_RDONLY);

But when we use a token generated from strtok(), it returns -1:

token = strtok(NULL, " ");
fd = open(token, O_RDONLY);

在注释中正确猜出了: token实际上不是与"a.txt"相同的字符串,但末尾包含额外的空格,这使得在打印为字符串时很难看清。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM