Store the positives in one vector and the negatives in another

Make an algorithm that reads a set of 30 integer numerical values and distributes them between two vectors, separating the positive from the negative numbers. Vectors should have 30 positions each. Show the vectors at the end of processing.

int vetPos[3], vetNeg[3];
int valor, i, cont;
cont = 1;

do{
    printf("Informe um valor: ");
    scanf("%d",&valor);

    if(valor >= 0){
        //insere no vetor positivo
        for(i=0;i<3;i++){
            vetPos[i] = valor;
        }            
    }else if(valor < 0){
        //insere no vetor negativo
        for(i=0;i<3;i++){
            vetNeg[i] = valor;
        }
    }
    valor = 0;
    cont++;
}while(cont<=3);


//saida de dados
printf("Os números positivos digitados foram: ");
for(i=0;i<3;i++){
    printf("%3d",vetPos[i]);
}
printf("\nOs números negativos digitados foram: ");
for(i=0;i<3;i++){
    printf("%3d",vetNeg[i]);
}

In do..while I did cont up to 3 just for the tests.

In the compiler the result was this:

Screen with error

I understand that this error occurs because it needs something like a delimiter for the vector, but not sure if that's it, what can I do?

Author: Maniero, 2018-07-28

1 answers

Is much simpler than this:

#include <stdio.h>

int main(void) {
    int pos[3], neg[3], posCount = 0, negCount = 0;
    for (int i = 0; i < 3; i++) {
        int valor;
        printf("Informe um valor: ");
        scanf("%d", &valor);
        if (valor < 0) neg[negCount++] = valor;
        else pos[posCount++] = valor;
    }
    printf("Os números positivos digitados foram: ");
    for (int i = 0; i < posCount; i++) printf("%d ", pos[i]);
    printf("\nOs números negativos digitados foram: ");
    for (int i = 0; i < negCount; i++) printf("%d ", neg[i]);
}

See working on ideone. E no repl.it. also I put on GitHub for future reference .

It doesn't make the slightest sense to have loops to fill the vector, which will make all positions have the same value and only the last value entered. It also makes no sense to have a else if when it is the exact opposite of if. It has too much variable and missing variables to control how many elements were inserted into each vector.

 4
Author: Maniero, 2020-07-27 19:50:44