我需要幫助將文本文件轉換爲C的二進制文件我不能繼續我的程序,即使我寫了一半,因爲我不知道是否打印任何值。轉換需要人,動物的最大長度,寬度,長度和字符串。基本上我正在寫的程序讀取二進制數據庫文件並返回滿足搜索的所有值。感謝您的幫助文本到二進制數據庫
#include <stdio.h>
#include <string.h>
typedef struct{
int max;
double length, width;
char people;
} max_t;
int
main()
{
FILE *database;
int inp, out;
database = fopen("database.txt", "r");
fscanf(database, "Max : %d", &max);
fscanf(database, "Width : %lf", &width);
fscanf(database, "Length : %lf", &length);
fscanf(database, "People : %s", &people);
fwrite(&max, 1, sizeof(max), database);
fwrite(&width, 1, sizeof(width), database);
fwrite(&length, 1, sizeof(length), database);
fwrite(&people, 1, sizeof(people), database);
database = fopen("out.txt", "wb");
return(0);
}
歡迎,並請學會如何先問一個適當的問題,這樣你會得到有用的回覆。 http://stackoverflow.com/questions/how-to-ask你不顯示任何代碼,或任何有價值的東西可以幫助別人幫助你。 – OldProgrammer 2013-04-23 00:43:21
謝謝你的歡迎。我沒有轉換代碼,因爲我的書很模糊。我一直在搜索stackoverflow和其他網站的高和低,沒有任何使用已經顯示出來。它似乎只是一個簡單的I/O,需要文本並返回與這些子字段的二進制文件,但我無法將其包圍。 – Hamas4 2013-04-23 00:45:06
顯示你擁有的並從那裏拿走它。 – 2013-04-23 00:46:06