生成的二进制码被保存在"data.exe"文件
请用VS Code中的Hex Editor或其他二进制编辑器查看
#include <stdio.h>
#include <stdlib.h>
void char_out();
void unsigned_char_out();
void short_out();
void unsigned_short_out();
void int_out();
void unsigned_int_out();
void long_out();
void unsigned_long_out();
void long_long_out();
void unsigned_long_long_out();
void float_out();
void double_out();
void long_double_out();
void print_question();
void switch_data_type(char data_type);
int main() {
print_question();
char data_type;
while (scanf("%c", &data_type)) {
if (data_type == 'q')
return 0;
printf("Now enter your number: ")
switch_data_type(data_type);
printf("file data.exe has been writen already!\n");
print_question();
while (getchar() != '\n') {}
}
return 0;
}
void print_question() {
printf("Please choose a data type:(q to quit)\n");
printf("1)char 2)unsigned char\n");
printf("3)short 4)unsigned short\n");
printf("5)int 6)unsigned int\n");
printf("7)long 8)unsigned long\n");
printf("9)long long A)unsigned long long\n");
printf("B)float C)double\n");
printf("D)long double\n");
printf("Enter your data type: ");
}
void switch_data_type(char data_type) {
switch (data_type) {
case '1':
char_out();
break;
case '2':
unsigned_char_out();
break;
case '3':
short_out();
break;
case '4':
unsigned_short_out();
break;
case '5':
int_out();
break;
case '6':
unsigned_int_out();
break;
case '7':
long_out();
break;
case '8':
unsigned_long_out();
break;
case '9':
long_long_out();
break;
case 'A':
unsigned_long_long_out();
break;
case 'B':
float_out();
break;
case 'C':
double_out();
break;
case 'D':
long_double_out();
break;
default:
break;
}
return;
}
void char_out() {
FILE* fa;
fa = fopen("data.exe", "w");
char number;
scanf("%hhd", &number);
fwrite(&number, sizeof(char), 1, fa);
fclose(fa);
}
void unsigned_char_out() {
FILE* fa;
fa = fopen("data.exe", "w");
unsigned char number;
scanf("%hhu", &number);
fwrite(&number, sizeof(unsigned char), 1, fa);
fclose(fa);
}
void short_out() {
FILE* fa;
fa = fopen("data.exe", "w");
short number;
scanf("%hd", &number);
fwrite(&number, sizeof(short), 1, fa);
fclose(fa);
}
void unsigned_short_out() {
FILE* fa;
fa = fopen("data.exe", "w");
unsigned short number;
scanf("%hu", &number);
fwrite(&number, sizeof(unsigned short), 1, fa);
fclose(fa);
}
void int_out() {
FILE* fa;
fa = fopen("data.exe", "w");
int number;
scanf("%d", &number);
fwrite(&number, sizeof(int), 1, fa);
fclose(fa);
}
void unsigned_int_out() {
FILE* fa;
fa = fopen("data.exe", "w");
unsigned int number;
scanf("%u", &number);
fwrite(&number, sizeof(unsigned int), 1, fa);
fclose(fa);
}
void long_out() {
FILE* fa;
fa = fopen("data.exe", "w");
long number;
scanf("%ld", &number);
fwrite(&number, sizeof(long), 1, fa);
fclose(fa);
}
void unsigned_long_out() {
FILE* fa;
fa = fopen("data.exe", "w");
unsigned long number;
scanf("%lu", &number);
fwrite(&number, sizeof(unsigned long), 1, fa);
fclose(fa);
}
void long_long_out() {
FILE* fa;
fa = fopen("data.exe", "w");
long long number;
scanf("%lld", &number);
fwrite(&number, sizeof(long long), 1, fa);
fclose(fa);
}
void unsigned_long_long_out() {
FILE* fa;
fa = fopen("data.exe", "w");
unsigned long long number;
scanf("%llu", &number);
fwrite(&number, sizeof(unsigned long long), 1, fa);
fclose(fa);
}
void float_out() {
FILE* fa;
fa = fopen("data.exe", "w");
float number;
scanf("%f", &number);
fwrite(&number, sizeof(float), 1, fa);
fclose(fa);
}
void double_out() {
FILE* fa;
fa = fopen("data.exe", "w");
double number;
scanf("%lf", &number);
fwrite(&number, sizeof(double), 1, fa);
fclose(fa);
}
void long_double_out() {
FILE* fa;
fa = fopen("data.exe", "w");
long double number;
scanf("%Lf", &number);
fwrite(&number, sizeof(long double), 1, fa);
fclose(fa);
}
标签:Code,Palace,void,数据类型,number,long,unsigned,fa,out
From: https://www.cnblogs.com/fjnhyzCYL/p/17060371.html