我试图在C中使用带有代码块的getline,但我无法让它在我的机器上运行。 代码也适用于我也可以访问的服务器,但是我的wifi访问受限,所以我需要这个才能在我的机器上运行。 我使用gcc编译器运行Windows 8.1 64位和13.12代码块。
这是使用getline的三个代码段之一,删除了一些额外的变量。
#include #include // For error exit() #include char *cmd_buffer = NULL; size_t cmd_buffer_len = 0, bytes_read = 0; size_t words_read; // number of items read by sscanf call bytes_read = getline(&cmd_buffer, &cmd_buffer_len, stdin); if (bytes_read == -1) { done = 1; // Hit end of file }
错误非常简单:
undefined reference to 'getline'
我怎样才能让它发挥作用?
编辑我添加了标题。 我还想提一下,我在这个网站上看到了一些对我不起作用的post。
也许这项工作。
#include #include #include ssize_t getdelim(char **linep, size_t *n, int delim, FILE *fp){ int ch; size_t i = 0; if(!linep || !n || !fp){ errno = EINVAL; return -1; } if(*linep == NULL){ if(NULL==(*linep = malloc(*n=128))){ *n = 0; errno = ENOMEM; return -1; } } while((ch = fgetc(fp)) != EOF){ if(i + 1 >= *n){ char *temp = realloc(*linep, *n + 128); if(!temp){ errno = ENOMEM; return -1; } *n += 128; *linep = temp; } (*linep)[i++] = ch; if(ch == delim) break; } (*linep)[i] = ' '; return !i && ch == EOF ? -1 : i; } ssize_t getline(char **linep, size_t *n, FILE *fp){ return getdelim(linep, n, 'n', fp); }
以上就是c/c++开发分享codeblocks和C未定义的getline引用相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/519390.html