#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
struct point_t
{
int x;
int y;
};
int save_points_b(const char *filename, const struct point_t* p, unsigned int N)
{
int zmienna = N;
if(filename == NULL || p == NULL || zmienna <= 0)
{
return 1;
}
FILE *plik;
plik = fopen(filename, "wb");
if(plik == NULL)
{
return 2;
}
int i = 0;
for(i = 0; i < zmienna; i++)
{
fprintf(plik, "%d ", (p+i)->x);
fprintf(plik, "%d\n", (p+i)->y);
}
fclose(plik);
return 0;
}
struct point_t* read(struct point_t* p)
{
if(p == NULL)
{
return NULL;
}
int x = 0;
int y = 0;
printf("Podaj x i y: ");
if(scanf("%d %d", &x, &y) != 2)
{
goto koniec;
}
(*p).x = x;
(*p).y = y;
return p;
koniec:
return NULL;
}
int main()
{
int liczba = 0;
struct point_t a[10001] = {0};
struct point_t *p = a;
char tab[31] = {0};
printf("Podaj liczbe: ");
scanf("%d", &liczba);
for(int i = 0; i < liczba; i++)
{
if(read(p+i) == NULL)
{
printf("Incorrect input");
return 1;
}
}
printf("Podaj nazwe pliku: ");
scanf("%30s[^\n]", tab);
save_points_b(tab, p, liczba);
return 0;
}
Oto mój kod. Z pobieraniem liczb wszystko jest dobrze. Problem pojawia się we wpisywaniu danych do pliku. Program do testowania zadania pokazuje błąd "Liczba danych zapisana do pliku powinna być wielokrotnością 4 bajtów" . Nie jestem sobie w stanie z tym poradzić, błagam o pomoc