#define SIZE 9
struct circ_buff{
char buff[SIZE];
int total = 0;
char *tail;
char *head;
} gsm;
"tail"& "head"에 액세스하는 방법을 알려줄 수 있습니까? 변수 gsm 사용 (gsm은 포인터가 아닌 struct 변수로 사용되어야 함).구조의 포인터 변수에 액세스
#define SIZE 9
struct circ_buff{
char buff[SIZE];
int total = 0;
char *tail;
char *head;
} gsm;
"tail"& "head"에 액세스하는 방법을 알려줄 수 있습니까? 변수 gsm 사용 (gsm은 포인터가 아닌 struct 변수로 사용되어야 함).구조의 포인터 변수에 액세스
#define SIZE 9
struct circ_buff{
char buff[SIZE];
int total; /* you can't initialize this here */
char *tail;
char *head;
} gsm;
int main() {
gsm.total = 0;
/* it looks like you're writing a circular buffer, so... set head/tail to the
* start of the buffer
*/
gsm.tail = gsm.buff;
gsm.head = gsm.buff;
/*
* gsm.head++; // increment as you add to the buffer, don't
* // forget to check for overflows
*
* // Other stuff you might want to do (assuming correct boundary checking)
*
* *gsm.head = 'G'; // set current head to 'G'
*
* printf("%c\n", *gsm.head); // print current value of head
*
*/
return 0;
}
gsm.tail[INDEX]
또는
*(gsm.tail)
int main(int argc, char **argv)
{
#define SIZE 9
struct circ_buff{
char buff[SIZE];
int total;
char *tail;
char *head;
} gsm;
strcpy(gsm.buff, "ohaiohai");
gsm.tail = gsm.buff;
gsm.head = gsm.buff;
printf("%s\n", gsm.buff);
printf("%s\n", gsm.tail);
printf("%s\n", gsm.head);
putchar(*(gsm.tail));
putchar(gsm.head[1]);
exit(0);
}
출력 :
$ gcc main.c && ./a.out
ohaiohai
ohaiohai
ohaiohai
oh
+1 : 좋은 답변과 stru의 기본 목적에 대한 좋은 추측을 위해 ct –
@Paul R : 내 DOS 시대에 키보드 버퍼의 많은 부분에 나를 생각 나게합니다 :) – forsvarir