Good morning, I was trying to fill a dynamic vector but when I print the input data i get something like this:
input: 1,5,3,4,2
output: 0,1,5,3,4
Could somebody help me I can't fix it I've been trying a lot and can't get it. I'll apreciatte so much (sorry for the english)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_STR 10
int vecto();
char seguir[MAX_STRLEN];
int var;
float* vector;
char* bv;
int vecto(){
int cont=0,ch;
char v[MAX_STR];
printf ("¿number of elements to order?: ");
scanf("%d",&var);
vector = (float*)malloc(var*sizeof(float));
while((ch = fgetc(stdin)) != EOF && ch != '\n' ){};
printf("input number press f for finish \n");
do{
fgets(v,sizeof(v),stdin);
if((strcmp(v,"f")!=0)){
cont++;
vector[cont]=strtod(v,&bv);
}
}while(!((cont==var) || (strcmp(v,"f")==0)));
printf("\n");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire