J
Jim
For some reason I keep getting the following error when compiling with
GCC. The program compiles and runs fine, but I get this error:
lab4b.c: In function 'main':
lab4b.c:47: warning: passing argument 1 of 'displayPtrArray' from
incompatible pointer type
** I'm doing this for a class that I'm taking so there might be a
better way to do it but I have to use an array of pointers.
-----------------------------
Below is my code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
// function prototypes
void displayArray(const double arr[], const int size);
void displayPtrArray(double const *arr[], const int size);
// main program
int main(void) {
double
x[SIZE] = {2.3, 5.66, 1.22, 5.6, 6.77, 3.2, 5.13, 2.82, 1, 5.01},
*xPtr[SIZE];
int cnt = 0;
// initialize the array with the pointer values
for(cnt = 0; cnt < SIZE; cnt++) {
xPtr[cnt] = &x[cnt];
}
// display array
printf("Orginal: ");
displayArray(x, SIZE);
printf("New : ");
displayPtrArray(xPtr, SIZE);
// sort the array
// display the original array again
}
void displayArray(double const arr[], const int size) {
int cnt = 0;
for(cnt = 0; cnt < size; cnt++)
printf("%5.2lf", arr[cnt]);
printf("\n\n");
}
void displayPtrArray(double const *arr[], const int size) {
int cnt = 0;
for(cnt=0; cnt < size; cnt++)
printf("%5.2lf", *arr[cnt]);
printf("\n\n");
}
GCC. The program compiles and runs fine, but I get this error:
lab4b.c: In function 'main':
lab4b.c:47: warning: passing argument 1 of 'displayPtrArray' from
incompatible pointer type
** I'm doing this for a class that I'm taking so there might be a
better way to do it but I have to use an array of pointers.
-----------------------------
Below is my code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
// function prototypes
void displayArray(const double arr[], const int size);
void displayPtrArray(double const *arr[], const int size);
// main program
int main(void) {
double
x[SIZE] = {2.3, 5.66, 1.22, 5.6, 6.77, 3.2, 5.13, 2.82, 1, 5.01},
*xPtr[SIZE];
int cnt = 0;
// initialize the array with the pointer values
for(cnt = 0; cnt < SIZE; cnt++) {
xPtr[cnt] = &x[cnt];
}
// display array
printf("Orginal: ");
displayArray(x, SIZE);
printf("New : ");
displayPtrArray(xPtr, SIZE);
// sort the array
// display the original array again
}
void displayArray(double const arr[], const int size) {
int cnt = 0;
for(cnt = 0; cnt < size; cnt++)
printf("%5.2lf", arr[cnt]);
printf("\n\n");
}
void displayPtrArray(double const *arr[], const int size) {
int cnt = 0;
for(cnt=0; cnt < size; cnt++)
printf("%5.2lf", *arr[cnt]);
printf("\n\n");
}