when compiling tells me it stopped working. pointers and vectors

-1

load a vector with 25 elements as maximum, and then to the values of that vector define which are even and odd, save them in two different vectors.

#include <stdio.h>
#include <stdlib.h>
#define N 25


void cargarvector(int vec[N],int tam);
void mostrarvec(int vec[N], int tam);
void seleccionar(int vec[],int vecA[],int vecB[] ,int *cantVA,int *cantVB,int tam);


int main()
{
    int vector[N],cant,vectorA[N],cantVA=0,vectorB[N],cantVB=0;
    printf("ingrese cantidad de valores para el vector 1 : ");
    scanf("%d",&cant);

    cargarvector(vector,cant);
    printf("\n");
    printf("vector 1\n");
    mostrarvec(vector,cant);
    seleccionar(vector,cant,vectorA,vectorB,&cantVA,&cantVB);
    printf("\n");
    mostrarvec(vectorA,cantVA);
    mostrarvec(vectorB,cantVB);

    return 0;
}
void cargarvector(int vec[N],int tam){
    int i;
    for(i=0;i<tam;i++){
        printf("ingrese los valores que desee : ");
        scanf("%d",&vec[i]);

}
}

void mostrarvec(int vec[N],int tam){
    int i;
    printf("[");
    for( i=0;i<tam;i++){
            printf("%d",vec[i]);


    }
    printf("]");

}

void seleccionar(int vec[],int vecA[],int vecB[],int *cantVA,int *cantVB,int cant){
    int i;
    for(i=0;i<cant;i++){

        if(vec[i]%2==0){
            vecA[*cantVA]=vec[i];
            (*cantVA)++;


        }else{
            vecB[*cantVB]=vec[i];
            (*cantVB)++;

        }

    }
}
    
asked by Florencia Gomez 25.11.2017 в 01:49
source

1 answer

0

You have this function:

void seleccionar(int vec[],int vecA[],int vecB[] ,int *cantVA,int *cantVB,int tam);

And then you make this call:

seleccionar(vector,cant,vectorA,vectorB,&cantVA,&cantVB);

If you review it a bit, you will see that the parameters are mixed badly. Expected (I understand) should be this:

seleccionar(vector,vectorA,vectorB,&cantVA,&cantVB,cant);

Try to read the error messages and warnings you receive when compiling ... they are very helpful !!! And it would not be bad for you to learn to use a code debugger ... programming without knowing how to debug the code is like having a car and not knowing how to drive ...

    
answered by 27.11.2017 в 13:01