由买买提看人间百态

topics

全部话题 - 话题: outputsize
(共0页)
h*****g
发帖数: 312
1
来自主题: JobHunting版 - fb面试题【转】
多谢你的解答 觉得 //1 处的outputSize 应该时刻更新吧?
char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;

while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
outpu... 阅读全帖
c*****n
发帖数: 96
2
来自主题: JobHunting版 - fb面试题【转】
char* readLine(){
static char[BUFSIZE] buf;
static char* ptr = buf;
static int bufSize = 0;
int outputSize = 0;
char *output = NULL;

while (1){
int pos = getNewLinePos(ptr, bufSize);
if (pos > 0){
// found new line char in the buffer
output = realloc(output, outputSize+pos+1); // one extra char for '
\0'
// TODO: check realloc return value
memcpy (output + outputSize, ptr, pos);
output[outputSize + pos] = '\0';
... 阅读全帖
(共0页)