1
#include "stdio.h"
struct book{
char title[50];
char author[50];
float value;
}library;
main(){
struct book library;
printf("now erter the book title");
gets(library.title);
printf("now erter the author");
gets(library.author);
printf("now enter the value.\n");
scanf("%f",&library.value);
printf("%s by %s : $%.2f\n",library.title,library.author,library.value);
printf("%s by %s : $%.2f\n",library.author,library.title,library.value);
printf("done.\n");
}
2
#include "stdio.h"
#define len 20
const char msgs[5][50]={/*也可为 *msgs[5](指针约等于数组 c 254页) 与msgs[5][50]相同 */
"thank you for the wonderful evening,",
"you certainly prove that a ",
"is a special kind of guy, we must get togher",
"over a delicious ",
" and have a few laughs "
};
struct names{
char first[len];
char last[len];
};
struct guy{
struct names handle;
char favfood[len];
char job[len];
float income;
};
int main(void){
struct guy fellow={
{"ewen","villard"},
"grilled salmon",
"personality coach",
58112.00
};
printf("dear %s, \n\n",fellow.handle.first);
printf("%s%s.\n",msgs[0],fellow.handle.first);
printf("%s%s.\n",msgs[1],fellow.job);
printf("%s\n",msgs[2]);
printf("%s%s%s",msgs[3],fellow.favfood,msgs[4]);
if(fellow.income>150000.0)
puts("!!");
else if(fellow.income>75000.0)
puts("!");
else
puts(".");
printf("\n%40s%s\n"," ","see you soon, ");
printf("%40s%s\n,"," ","shalala");
return 0;
}