-1

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 ?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Toyama70
  • 23
  • 3
  • Maybe `min` is a macro defined somewhere in your header files. You could try to rename `min` variable to another name. – Robert Jul 22 '21 at 09:51
  • 1
    `(...)` enclosing the first function is not `{...}`. – David C. Rankin Jul 22 '21 at 09:52
  • Welcome to SO! Please choose a title that describes your technical problem that others might search for. – user438383 Jul 22 '21 at 09:52
  • A few links that provide basic discussions of pointers may help. [Difference between char *pp and (char*) p?](https://stackoverflow.com/a/60519053/3422102) and [Pointer to pointer of structs indexing out of bounds(?)...](https://stackoverflow.com/a/60639540/3422102) (ignore the titles, the answers discuss pointer basics) – David C. Rankin Jul 22 '21 at 09:53

1 Answers1

2

You need to use {} instead of () for function body

void decoupeMinutes (int* heur, int* min)
( // wrong, use {
    *heur = *min / 60;
    *min = *min % 60;
) // wrong, use }
Anubhav Gupta
  • 421
  • 5
  • 12