Question: My code compiles in CodeBlocks but I am getting warnings concering the countZerosOnes function and the pointers. I cannot figure out why or how to

My code compiles in CodeBlocks but I am getting warnings concering the countZerosOnes function and the pointers.

I cannot figure out why or how to fix it?

#include #include #define MAX 100

// Displays array void display (int data[MAX], int size);

// Reverses order of array void reverse (int data[MAX], int size);

// Counts number of zeros and ones in array int countZerosOnes (int data[MAX], int size, int *pNumZeros, int *pNumOnes);

int main (void) { FILE *fp; int size = 0; // Size of array int numZeros; // Number of zeros in array int numOnes; // Number of ones in array int totalCount; // Number of zeros and ones in array

int data[MAX]; // Array

int i; int *pNumOnes; int *pNumZeros;

// Part 1: Opens file fp = fopen("data.txt", "r");

if(fp == NULL) { printf("File does not exist! "); exit(-1); }

// Loops to assign values into array and find the size for(i=0; fscanf(fp, "%d ", &size) != EOF; i++) { data[i] = size; size = i + 1; }

// Part 2: Display the array printf("Original Data: "); display (data, size);

// Part 3: Reverse the array reverse (data, size);

// Part 4: Count zeros and ones countZerosOnes (data, size, &pNumZeros, &pNumOnes); totalCount = countZerosOnes (data, size, &pNumZeros, &pNumOnes); printf(" Number of zeros in original array = %d", pNumZeros); printf(" Number of ones in original array = %d", pNumOnes); printf(" Total count of ones & zeros = %d ", totalCount);

return 0; }

// Code Part 2: Function to display array void display (int data[MAX], int size) { int j = 0; printf("==> ");

for(j=0; j { printf("%d ", data[j]); } }

// Code for Part 3: Function to reverse array void reverse (int data[MAX], int size) { int temp; int start; int end = size - 1;

// Loops until the array has been flipped for(start=0; start<(size/2); start++, end--) { temp = data[start]; // Temp holds original data data[start] = data[end]; // Flips array data[end] = temp; // Original data given to end }

printf(" Flipped Data: "); display(data,size);

} // Code for Part 4: Function to count zeros and ones countZerosOnes (int data[MAX], int size, int *pNumZeros, int *pNumOnes) { int i; int numZeros = 0; int numOnes = 0;

// Loops to find number of zeros in array for(i=0; i { if(data[i] == 0) numZeros++; }

//Loops to find number of ones in array for(i=0;i { if(data[i] == 1) numOnes++; }

*pNumZeros = numZeros; *pNumOnes = numOnes;

return(numZeros + numOnes); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!