1. 程式人生 > >‘(’向後緊跟,‘)’、‘,’、‘;’向前緊跟,緊跟處不留空格

‘(’向後緊跟,‘)’、‘,’、‘;’向前緊跟,緊跟處不留空格

類型 his col you 數組 str user ges 變量

‘(’向後緊跟,‘)’、‘,’、‘;’向前緊跟,緊跟處不留空格。

 1 #include <iostream>
 2 #include<stdio.h>
 3 #define size 3
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 
 6 
 7 using namespace std;
 8 //定義book結構類型
 9 struct book
10 {
11     char   title[20];
12 char author[15]; 13 int pages; 14 float price; 15 }; 16 //book結構的輸入函數 17 input_book(book& bk,char *name) 18 { 19 cout<<name<<":"<<endl; 20 cout<<"title:"; 21 cin>>bk.title; 22 cout<<"author:"; 23 cin>>bk.author; 24 cout<<"
pages:"; 25 cin>>bk.pages; 26 cout<<"price:"; 27 cin>>bk.price; 28 } 29 //book結構的輸出函數 30 output_book(book& bk,char *name) 31 { 32 cout<<name<<": "; 33 cout<<bk.title<<" "; 34 cout<<bk.author<<" "; 35 cout<<bk.pages<<"
"; 36 cout<<bk.price<<endl; 37 } 38 39 int main(int argc, char** argv) { 40 //聲明變量和結構數組 41 int i; 42 char str[20]; 43 book bk[size]; 44 45 //輸入結構數組 46 for(i=0;i<size;i++) { 47 sprintf(str,"bk[%d]",i+1); 48 input_book(bk[i],str); 49 } 50 51 //顯示結構數組 52 for(i=0;i<size;i++) { 53 sprintf(str,"bk[%d]",i+1); 54 output_book(bk[i],str); 55 } 56 return 0; 57 58 }

‘(’向後緊跟,‘)’、‘,’、‘;’向前緊跟,緊跟處不留空格