错在哪里了呢?一运行就死
要求Define a structure type element_t to represent one element from the periodic table of elements.以下是代码
程序代码:
#include<stdio.h> struct element_t {int number; char name[20]; char symbol[2]; float weight; int array[7]; }; void main() {void scan_element(struct element_t *p); void printf_element(struct element_t *p); struct element_t ele; struct element_t *p; p=&ele; scan_element(p); printf_element(p); } void scan_element(struct element_t *p) {int i; printf("\nPlease input some informations of one element:\n\nThe atomic number\nThe name\nChemical symbol\nA numeric field for the atomic weight\nA seven-element array of the integers for the number of electrons in each shell\n\n"); scanf("%d%s%s%f",&(*p).number,&(*p).name,&(*p).symbol,&(*p).weight); for(i=0;i<7;i++) scanf("%d",&(*p).array[i]); } void printf_element(struct element_t *p) {int i; printf("\nAtomic number: %d\nName: %s\nChemical symbol: %s\nAtomic weight: %f\n",(*p).number,(*p).name,(*p).symbol,(*p).weight); printf("Number of electrons in each shell is: "); for(i=0;i<7;i++) printf("%d ",(*p).array[i]); }