So, I am learning how to use pointers, but although my code is almost identical to the one of the lessons I am following, I keep of getting compiling errors.
First, here is my code :
#include <stdlib.h>
void decoupeMinutes(int* heur, int* min);
int main (int argc, char *argv[])
{
int heures = 0;
int minutes = 90;
decoupeMinutes(&heures, &minutes);
printf("%d heures et %d minutes", heures, minutes);
return 0;
}
void decoupeMinutes (int* heur, int* min)
(
*heur = *min / 60;
*min = *min % 60;
)
Now, here are the errors I get when trying to compile :
heure.c:20:11: error: use of undeclared identifier 'min'; did you mean 'main'? *heur = *min / 60; ^~~ main
Then :
heure.c:20:15: error: invalid operands to binary expression ('int (int, char **)' and 'int') *heur = *min / 60; ~~~~ ^ ~~
Also :
heure.c:20:19: error: expected ')' *heur = *min / 60; ^
Also :
heure.c:18:21: error: function cannot return function type 'void (int )' void decoupeMinutes (int heur, int* min) ^
And :
heure.c:21:9: error: initializer element is not a compile-time constant *min = *min % 60; ^~~~~~~~~
Now, what I don't understant, is that the code in the lesson I am following is very similar to mine I think :
#include <stdio.h>
#include <stdlib.h>
void decoupeMinutes(int* pointeurHeures, int* pointeurMinutes);
int main(int argc, char *argv[])
{
int heures = 0, minutes = 90;
decoupeMinutes(&heures, &minutes);
printf("%d heures et %d minutes", heures, minutes);
return 0;
}
void decoupeMinutes(int* pointeurHeures, int* pointeurMinutes)
{
*pointeurHeures = *pointeurMinutes / 60;
*pointeurMinutes = *pointeurMinutes % 60;
}
This last one compiles without any error. So, what am I not seeing there ?