Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAXPUNKTE 16
- void DemoSave() {
- double feldX[MAXPUNKTE] = { 10, 20, 30, 40 };
- double feldY[MAXPUNKTE] = { 15, 25, 35, 45 };
- int feldLen = 4;
- FILE *file = fopen("demo.txt", "w");
- if (file != NULL) {
- for (int i = 0; i < feldLen; i++) {
- fprintf(file, "%.2lf %.2lf\n", feldX[i], feldY[i]);
- }
- fclose(file);
- }
- }
- void DemoLoad() {
- double feldX[MAXPUNKTE];
- double feldY[MAXPUNKTE];
- int feldLen = 0;
- FILE *datei = fopen("demo.txt", "r");
- if (datei != NULL) {
- while (fscanf(datei, "%lf %lf", &feldX[feldLen], &feldY[feldLen]) == 2) {
- feldLen++;
- if (feldLen >= MAXPUNKTE) {
- break; // too much
- }
- }
- fclose(datei);
- }
- for (int i = 0; i < feldLen; i++)
- {
- printf("%3i. Punkt: x : %lf\n", i + 1, feldX[i]);
- printf(" y : %lf\n", feldY[i]);
- }
- }
- int main(void)
- {
- DemoSave();
- DemoLoad();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement