Use %lf with scanf for type double .
[edit]But there are a number of indirection issues as well...
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
You have too much indirection.
#include <stdio.h>
#define MAX 10
void sort( double* n, int q );
void print_nums( double* n, int q );
int main( void ) {
double nums[MAX];
int i;
for( i = 0; i < MAX; i++ ) {
printf( "Please enter a double variable: " );
scanf( "%lf", &nums[i] );
}
sort( nums, 10 );
print_nums( nums, 10 );
return 0;
}
void sort( double* n, int q ) {
int a, b;
double x;
for( a = 1; a < q; a++ ) {
for( b = 0; b < q - 1; b++ ) {
if( n[b] > n[b + 1] ) {
x = n[ b ];
n[b] = n[b + 1];
n[b + 1] = x;
}
}
}
}
void print_nums( double* n, int q ) {
int count;
for( count = 0; count < q; count++ )
printf( "\n%f", n[count] );
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
double* n[]
uses double indirection? If so, can you explain? I assumed it translated to:
'n' is an array (unspecified length) of pointers to type double.
Not in a function prototype -- there it is a pointer to a pointer to double. You may want to peruse the earlier c-faq.com link again.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314