I have an assignment to write a function that dynamicly initialize an array from struct that is in the header file. and for some resone I am keep getting the same error "uninitialized local variable 'columnData' used this is the header file
#ifndef QUEUE_H
#define QUEUE_H
/* a queue contains positive integer values. */
typedef struct queue
{
int arraySize;
int* column;
} queue;
void initQueue(queue* q, unsigned int size);
void cleanQueue(queue* q);
void enqueue(queue* q, unsigned int newValue);
int dequeue(queue* q); // return element in top of queue, or -1 if empty
#endif /* QUEUE_H */
this is my code:
#include <iostream>
#include "queue.h"
int main()
{
queue* columnData;
unsigned int size = 0;
std::cout << "Please enter column size: ";
std::cin >> size;
initQueue(columnData, size);
printf("%d", &columnData->column[0]);
}
void initQueue(queue* q, unsigned int size) {
q->column = new int[size];
q->column[0] = 5;
}
void cleanQueue(queue* q) {
}
void enqueue(queue* q, unsigned int newValue) {
}
int dequeue(queue* q) {
return 1;
}
If someone can help me it will be great.
columnDataa value inmain, then you read that uninitialized value to pass to a function. You might want to havequeue columnDataand pass it as&columnDatato your functions. Better would be to take all those functions and make them members ofqueue.