Help, I am getting a segmentation error.
Basically I need a function to print out certain elements of an array. I have created the functions displayArrayVal1 and displayArrayVal2.
x_array and y_array are both global. Where am I going wrong?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <inttypes.h>

uint16_t x_array[8]={1,2,3};
uint32_t y_array[2]={4,5};

void displayArrayVal1(uint16_t x[8]);
void displayArrayVal2(uint32_t y[2]);

int main(int argc, char *argv[])
{

displayArrayVal1( x[8]);
displayArrayVal2 ( y[2]);

return 0;
}

void displayArrayVal1 (uint16_t x_ array [8])
{
printf("X-array1 = %"PRIu16" , x_array [0]);
}

void displayArrayVal2 (uint32_t y[2])
{
printf("Y-array1 = %"PRIu32" , y_ array [0]);
}

THis is the error I am getting:

warning: passing argument 1 of .displayArrayVal1’ makes pointer from integer without a cast [enabled by default]
expected 'uint16_t *' but argument is of type 'uint16_t'
warning: array subscript is above array bounds [-Warray-bounds]

Change lines 22 and 27 to match the function prototypes in lines 10 and 11.
You need to pass the correct variable name to each function.
e.g. displayArrayVal1( x_array);

The printf lines need fixing to something like:
printf("X-array1 = %u\n", x[0]);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.