printf("Đọc trả về : %d\n", readPointFromFile(fileName, &p2));
showPoint(&p2);
trả về trạng thái thoát; }
void khởi tạoPoint(Điểm * p){ printf("Entrez une value pour x : "); scanf("%f", &p->x); printf("Entrez une value for y : "); scanf("%f", &p->y); } void showPoint(Điểm * p){ printf("Le point est aux coordonnées (x,y) = (%.2lf, %.2lf).\n", p->x, p->y); } void khởi tạoFileName(char * fileName){ printf("Entrez une value pour le nom de fichier : "); scanf("%s", fileName); } int writePointToFile(char *tên tệp, Điểm * p) { TẬP TIN* f2 = NULL;
f2 = fopen(tên file, "wb");
if(f2 != NULL){ if(fwrite(&p, sizeof(struct Point), 1, f2) != 1){ printf("Không thể ghi vào tập tin."); fclose(f2); return -1; } } khác { printf("Không thể mở tập tin."); return -1; } fclose(f2); return 0; } int readPointFromFile(char * fileName, Point * p){
TẬP TIN* f = NULL;
f = fopen(fileName, "rb");
if(f != NULL){ if(fread(&p, sizeof(struct Point), 1, f) != 1){ printf("Không thể đọc được từ tập tin."); fclose(f); return -1; } } khác{ printf("Không thể mở tập tin."); return -1; } fclose(f); return 0; }
Đây là nhật ký của tôi:
/home/sviktor/CLionProjects/untitled/cmake-build-debug/untitled Entrez une valeur pour x : 2.33 Entrez une valeur pour y : 1.34 Le point aux coordonnées (x,y) = (2.33, 1.34). Tên cá nhân : test123.bin Vous avez enré : test123.bin Viết trả về : 0 Đọc trả về : 0 Le point aux coordonnées (x,y) = (0,00, 0,00).
Quá trình kết thúc với mã thoát 0
Tôi đang sử dụng Fedora và clion IDE,
Biên tập viên Bless nói rằng tệp test123.bin của tôi chứa cái này C4 2E 18 F1 FC 7F 00 00 Nhưng chức năng đọc không hoạt động (nó cho điểm = (0,0))
Tôi là một lập trình viên xuất sắc, rất giỏi!