Problems when calling a function in C

0

Within this program, which is shared memory in C, I have an error in compiling it, it tells me that there is an implicit statement inside the switch that is where I send the function, does anyone know how I can solve it?

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

int main(int argc, char *argv[])
{

int shmid, *variable;
key_t llave;
//1 
llave = ftok(argv[0], 'K');
if((shmid = shmget(llave, sizeof(int), IPC_CREAT | 0600)) == -1)
{
    perror("Error en shmget");
    exit(-1);
}
/*nos atamos a la memoria compartida*/
if((variable = (int *)shmat(shmid, NULL, 0)) == (int *)(-1))
{
perror("Fallo shmat");
exit(-1);
}

while(1)
{
    printf("\nIntroduzca m para modificar el valor de la variable, v para        visualizarla y t para terminar:\n ");
    switch(leer_car())
   {
       case 't':
           /*Libera la memoria compartida*/
           shmctl(shmid, IPC_RMID,0);
           exit(0);

       case 'v':
           /*visualiza la variable*/
            printf("variable =%d\n", *variable);
            break;
       case 'm':
            printf("Nuevo valor de la variable en memoria compártida:\n");
            scanf("%d", variable);
            break;
       default:
            printf("Se indtrodujo una letra incorrecta =%d \n",  *variable);
            break;
         }
          }
          }

     int leer_car()
     {
        char letra;
        char almacen[80];

        scanf("%s", &*almacen);
        scanf(almacen, "%c", &letra);
         return letra;
      }
    
asked by Daniel R 13.04.2018 в 02:23
source

1 answer

0

What happens is that the compiler C requires the signature or definition of the function leer_car() before the moment that the program will actually use it. Anyway in this case is a warning that does not conspire with the compilation and generation of the executable, however to correct this, just before the main() you declare the function:

int leer_car(void);

Or failing that, you should "upload" the whole routine before main() .

    
answered by 13.04.2018 / 04:15
source