|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <string.h>
char * s_gets(char * st,int n);
#define MAXTITL 41
#define MAXAUTL 31
struct book
{
char title[MAXTITL];
char author[MAXAUTL];
float value;
};
int main()
{
struct book library;//library 为struct book 型变量;
printf("请输入书名:\n");
s_gets(library.title,MAXTITL);
printf("现在输入作者:\n");
s_gets(library.author,MAXAUTL);
printf("现在输入价格:\n");
scanf("%f",&library.value); /*问题1--程序运行到这里就崩溃了。。*/
printf("%s by %s is %.2f\n",library.title,library.author,library.value);
printf("Done\n");
return 0;
}
char * s_gets(char * st,int n)
{
char * ret_val;
char * find;
ret_val = fgets(st,n,stdin); /*问题2---stdin是什么意思*/
if (ret_val)
{
find = strchr(st,'\n');
if (NULL)
{
*find = '\n';
}
else
{
while (getchar()!='\n')
{
continue;
}
}
}
return ret_val;
} |
|