|
藍森林 http://www.lslnet.com 2006年6月6日 10:18
[高手請看]有一條C語句我讀不明白?
for (inchars = 0; inchars < outchars; inchars+=n ) {
n = read(s, &buf[inchars], outchars - inchars);
printf("n is %d\n",n);
if (n < 0)
errexit("socket read failed: %s\n",
strerror(errno));
什麼意思?
inchars+=n ?
outchars - inchars ? |
[高手請看]有一條C語句我讀不明白?
就是把錯誤碼譯成人能看懂的字符串顯示出來
比如:no such file or command
之類的。 |
[高手請看]有一條C語句我讀不明白?
就是把錯誤碼譯成人能看懂的字符串顯示出來
比如:no such file or command
之類的。 |
[高手請看]有一條C語句我讀不明白?
可能我沒有說清楚,我說的是「整個這個循環」表達的是什麼意思。
inchars+=n 和outchars - inchars,在這個循環中起什麼作用?
for (inchars = 0; inchars < outchars; inchars+=n ) {
n = read(s, &buf[inchars], outchars - inchars);
printf("n is %d\n",n);
if (n < 0)
errexit("socket read failed: %s\n",
strerror(errno));
} |
[高手請看]有一條C語句我讀不明白?
就是保證讀到的數據長度一定是 outchars 個字節。 |
[高手請看]有一條C語句我讀不明白?
為了保證能夠完整地讀完描述字中的數據,有人習慣採用類似上面的辦法。 |
[高手請看]有一條C語句我讀不明白?
從s中讀取數據到buf串直到outchars個為止
inchars+=n就好理解了,buf串順序存放
outchars - inchars是想讀這麼多個字符,想,但一定能讀,所以才有for
Reads data from a file.
int _read(
int handle,
void *buffer,
unsigned int count
); |
| |