Witam.
Mam problem z wskaźnikami. Mianowicie chce mieć funkcje typu void w pliku lib.c a zmienne w main.c. Całość wygląda tak:
main.c
#include "lib.h"
int main()
{
int n;
wczytaj_wymiar(&n, "Podaj wymiar tablicy, n= ");
double tab[n];
wczytaj_tablice(n, &tab, "Podaj %i element tablicy. ");
minimum(n, tab, "Najmniejszy element tablicy to %lf\n");
maksimum(n, tab, "Najwiekszy element tablicy to %lf\n");
return 0;
}
lib.c
#include<stdio.h>
void wczytaj_wymiar(int *n, char *prompt)
{
printf(prompt);
scanf("%i", n);
}
void wczytaj_tablice(int n, double *tab, char *prompt)
{
int i;
for (i = 0; i < n; i++) {
printf(prompt, i);
scanf("%i", tab[i]);
}
}
void minimum(int n, double tab[n], char *prompt)
{
int min = 0, i;
for (i = 0; i < n; i++) {
if (tab[i] < tab[min])
min = i;
}
printf(prompt, tab[min]);
}
void maksimum(int n, double tab[n], char *prompt)
{
int max = 0, i;
for (i = 0; i < n; i++) {
if (tab[i] > tab[max])
max = i;
}
printf(prompt, tab[max]);
}
lib.h
#ifndef SMT__LOCAL_LIB
#define SMT__LOCAL_LIB
void wczytaj_wymiar(int *, char *);
void wczytaj_tablice(int n, double *, char *);
void minimum(int n, double tab[n], char *);
void maksimum(int n, double tab[n], char *);
#endif
przy kompilacji wyskakuje to:
main.c: In function â€main’:
main.c:13:5: warning: passing argument 2 of â€wczytaj_tablice’ from incompatible pointer type
lib.h:8:6: note: expected â€double *’ but argument is of type â€double (*)[(unsigned int)(n)]’
Jak mogę rozwiązać ten problem?