如何删除fgets中的换行符
普通数组我测试过可以删除,但把字符串存到结构体中的数组就不行了,请问这是怎么回事?
#include <stdio.h>struct
#include <string.h>
struct human
{
char name[20] ;
};
int main (void)
{
char name2[20] ;
struct human xing ;
struct human * pst = &xing ;
fgets(pst->name,19,stdin);
if(pst->name[strlen(pst->name) - 1] == '\n')
pst->name[strlen(pst->name) - 1] == '\0' ;
scanf("%s",name2) ;
printf("name = %s",pst->name) ;
printf("name2 = %s",name2) ;
return 0 ;
}