程序從讀取用戶輸入的firstname,lastname和prize,并將他們讀取的值按照一定格式存儲(chǔ)到另一個(gè)字符串?dāng)?shù)組內(nèi)。
#include<stdio.h>
#define MAX 20
int main(void)
{
char first[MAX];
char last[MAX];
char formal[2*MAX+10];
double prize;
puts("Enter your first name");
gets(first);
puts("Enter your last name");
gets(last);
puts("Enter your prize money");
scanf("%lf",&prize);
sprintf(formal,"%s,%-19s:$%6.2f\n",last,first,prize);
puts(formal);
getchar();
getchar();
return 0;
}