datasize.c (1023B)
1 /* Exercise 11.16 */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 #define BUF 255 7 8 int main(void) 9 { 10 FILE *fd; 11 12 if( (fd = fopen("datasize.dat", "w")) == NULL) { 13 printf("%s: cannot open the file\n", "datasize.dat"); 14 exit(-1); 15 } 16 17 fprintf(fd, "%-30s%4s\n", "Data type", "Size"); 18 fprintf(fd, "%-30s%4d\n", "char", sizeof(char)); 19 fprintf(fd, "%-30s%4d\n", "unsigned char", sizeof(unsigned char)); 20 fprintf(fd, "%-30s%4d\n", "short int", sizeof(short int)); 21 fprintf(fd, "%-30s%4d\n", "unsigned short int", sizeof(unsigned short int)); 22 fprintf(fd, "%-30s%4d\n", "int", sizeof(int)); 23 fprintf(fd, "%-30s%4d\n", "unsigned int", sizeof(unsigned int)); 24 fprintf(fd, "%-30s%4d\n", "long int", sizeof(long int)); 25 fprintf(fd, "%-30s%4d\n", "unsigned long int", sizeof(unsigned long int)); 26 fprintf(fd, "%-30s%4d\n", "float", sizeof(float)); 27 fprintf(fd, "%-30s%4d\n", "double", sizeof(double)); 28 fprintf(fd, "%-30s%4d\n", "long double", sizeof(long double)); 29 30 return 0; 31 } /* E0F main */ 32