我工作的C,以下是我的代码:使用getline()从标准输入读取整行时出现意外输出?
#define _GNU_SOURCE
#include<stdio.h>
#include<stdlib.h>
int main()
{
char* str = NULL;
size_t n;
printf("Enter the string : \n");
getline(&str, &n, stdin);
printf("Initial string is : (%s)\n", str);
return 0;
}
当我运行上面的程序它提供了以下的输出:
Enter the string :
bsalunke
Initial string is : (bsalunke
)
什么可能有意想不到的字符串的理由获得存储在str
指针(即它是一个有很多空白的字符串)? 林使用gcc 4.1.2版本在Linux
@uab感谢您的回答,在了解问题 – BSalunke 2013-03-07 10:21:55