Problem with functions and arrays [duplicated]

2

I do not understand why the program does not do what I order in the functions and it simply prints on the screen the two "printf" that I use test in the main.

#include <stdio.h>
#define MAX 10
void leerVect(int vect[MAX]);
void escribirVect (int v[MAX], int tam);


int main ()
{
    int v[MAX], tam=10;

    printf("empezamos\n");


    void leerVect(v);
    void escribirVect (v, tam);


    printf("Terminamos");



    return 0;
}

void leerVect(int v[MAX])
{
    int i;
        for (i=0; i<MAX && v[i]!=0; i++)
        {
            printf("Introduzca el valor de v[%d]\n", i);
            scanf("%d", &v[i]);
        }
}

void escribirVect (int v[MAX], int tam)
{
    int i;
    for (i=0; i<tam; i++)
    {
        printf("El valor de v[%d] es: %d \n", i, v[i]);
    }
}
    
asked by ppedro9 28.10.2018 в 15:28
source

1 answer

1

That's because in the main function when you call the functions leerVect and escribirVect you should not write void that means that the function will not return any value and is only used when you are going to declare functions.

It would be as follows:

int main ()
{
    int v[MAX], tam=10;

    printf("empezamos\n");

    //Aqui no debe llevar void cuando llamas a las funciones
    leerVect(v);
    escribirVect (v, tam);


    printf("Terminamos");



    return 0;
}
    
answered by 28.10.2018 в 20:50