#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define MAX_VECTORS 4
#define SIZE 100
int main( void )
{
double **vectors = NULL;
int *lengths = NULL;
vectors = (double **) malloc (MAX_VECTORS * sizeof(double *));
lengths = (int *) malloc (MAX_VECTORS * sizeof( int ));
char input[SIZE];
int precision = 2; //defualt precision.
char spec;
double *elements = NULL;
elements = (double *) malloc (MAX_VECTORS * sizeof(double *));
int length;
while( strcmp(input, "bye") != 0){ // Repeats calc until the user enters bye.
printf("calc>\n");
scanf("\n");
gets(input);
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<stdlib.h>
- #define MAX_VECTORS 4
- #define SIZE 100
- int main( void )
- {
- double **vectors = NULL;
- int *lengths = NULL;
- vectors = (double **) malloc (MAX_VECTORS * sizeof(double *));
- lengths = (int *) malloc (MAX_VECTORS * sizeof( int ));
- char input[SIZE];
- int precision = 2; //defualt precision.
- char spec;
- double *elements = NULL;
- elements = (double *) malloc (MAX_VECTORS * sizeof(double *));
- int length;
-
- while( strcmp(input, "bye") != 0){ // Repeats calc until the user enters bye.
- printf("calc>\n");
- scanf("\n");
- gets(input);
Say the input is A 3 5 4 2, I want to read A to be a specifier, 3 to be the length of an array, as int, and then the elements of the array as double data type(3 elements).
I was able to get the length and the specifier by using:
sscanf(input,"%c\n%d\n", &spec, &length);
how can I get the elements as double data type?
Thank you.