ret = sscanf(p,"%*s %1024s",request);
if(ret!=1){
...
}
p
是"GET /index.html", 这行代码的意思是说直接取"/index.html", 跳过前面的"GET ".
这种用法, 避免定义一个哑变量
.
int len = sprintf(buf, "%.*s", LEN, str);�
最多写LEN
个字符到buf
.
切记不要写下面这种 ad hoc 的代码:
int len = sprintf(buf, "%2047s", str);
If the output was trun- cated due to this limit then the return value is the number of charac- ters (not including the trailing ’\0’) which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated. (See also below under NOTES.) If an output error is encountered, a negative value is returned.
很cool啊~