좋습니다. 내가하고있는이 프로젝트에서 결승선을 볼 수 있습니다. 배열에서 값을 반환하려고 할 때 왜 배열이 NULLS를 뱉어 내는지 알기 위해 노력하고 있습니다. 내 enquue 함수가 작동한다고 확신하고 주소에서 값을 가져 오는 것이 확실합니다. 포인터가 참조합니다. 이것은 내가 가진 코드입니다. 나는 보드를 과부하하고 싶지 않았기 때문에 의도적으로 내 주요 기능을 포함하지 않았다. 그러나 문제를 진단 할 필요가 있다면 알려 주시기 바랍니다.배열을 비우는 데 도움이 필요합니다.
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// the capacity of the queue
#define CAPACITY 10
// a queue
typedef struct
{
// the index of the first element in the queue
int head;
// storage for the elements in the queue
char* strings[CAPACITY];
// the size of the queue
int size;
}
queue;
// declare a queue (as a global variable)
queue q;
/*
* Puts a new element into the queue into the "end" of the data structure
* so that it will be retrived after the other elements already in the
* queue.
*/
bool enqueue(char* str)
{
int rear = 0; // back of the queue
if (q.size==CAPACITY)
{
return false;
}
else
{
rear = (rear + 1) % CAPACITY;
q.strings[rear] = str;
printf("%s", q.strings[rear]);
q.size++;
return true;
}
}
/**
* Retrieves ("dequeues") the first element in the queue, following the
* the "first-in, first-out" (FIFO) ordering of the data structure.
* Reduces the size of the queue and adjusts the head to the next element.
*/
char* dequeue(void)
{
char *charHead = NULL;
if (q.size)
{
charHead = malloc(sizeof(char)) ;
char *chpointer = malloc(sizeof(strArray[12]));
q.head++;
q.head = q.head%CAPACITY;
charHead = q.strings[q.head];
return charHead;
}
// Return null character if queue is empty
return NULL;
}
'strArray '란 무엇입니까? 들여 쓰기를 시도해보십시오.'[code]'를 사용할 필요가 없습니다. 4 칸만큼 들여 쓰고 그 다음에 코드를 들여 씁니다. – unwind