//*book.c
#include<stdio.h>
#include<string.h>
#include<stdlib.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 (void)
{
struct book library;
printf("please enter the book title:\n");
s_gets(library.title,MAXTITL);
printf("NOW enter the author.\n");
s_gets(library.author,MAXAUTL);
printf("enter the value.\n");
// s_gets(library.value);
scanf("%f",&library.value);
printf("%s by %s: $%.2f\n,library.title, library.author, library.value");
printf("%s: \"%s\" ($%.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);
if(ret_val);
{
find =strchr(st,'\n');
if(find)
{
*find="\0";
}
else
{
while(getchar()!="\n")
continue;
}
//D:\app download\CodeBlocks (code )\2024 code\test-3-30\main.cpp|9|error: array bound is not an integer constant before ']' token|
return ret_val;
}
}
//代码如果有问题欢迎指出
//谢谢