test

#include<stdio.h> #include<stdlib.h> enum ObjType { Ball = 1, Cube, Pyramid, Cylinder }; enum Material { Iron = 1, Aluminum, Lead }; struct information { int id; ObjType type; Material material; float para1[10]; float para2[10]; float volume; float weight; char error[1000]; }; typedef struct information data; void writedatatofile(data info[], int size, FILE*fp); int readdatatofile(data info[], FILE*fp); #define FILE_ORIGIN"origin.txt" int main() { int select; printf("0. Exit\n1. Open file and Show Data\n2. Data operations\n3. Sort operations\n4. Save Data to file\n5. Clear screen\n"); printf("==============================\n"); while(1) { printf("Please select an option\n"); scanf_s("%d", &select); switch (select) { case 0: printf("Exit\n"); break; case 1: { int size; data info[1000]; FILE*fp = NULL; errno_t err; err = fopen_s(&fp, FILE_ORIGIN, "r"); if (0 != err) { printf("file could not be opened\n"); return; } else { size = readdata(info, fp); printdata(info, size); fclose(fp); } } break; case 2: break; case 3: break; case 4: break; case 5: system("cls"); printf("0. Exit\n1. Open file and Show Data\n2. Data operations\n3. Sort operations\n4. Save Data to file\n5. Clear screen\n"); printf("==============================\n"); break; default: printf("Error selection. Please enter again.\n"); } if (0 == select) break; } system("pause"); } void writedatatofile(data info[], int size, FILE*fp) { } int readdatatofile(data info[], FILE*fp) { int ix = 0; while(fp.get() != EOF) { scanf int int int float float (看你要做5次 還是一次讀5個) info[ix] -> id = 讀出來的id ... . . . info[ix] -> volume = calculateVolume(*this); info[ix] -> weight = calculateWeight(*this); ix++; } } float calculateVolume(data input) { switch (input.type) { 算體積 } return 體積; } float calculateWeight(data input) { switch (input.material) { 算重量 } return 重量; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.