Dưới đây là code về cái buffer của em...Em làm bài tập hệ điều hành nhưng khi chạy case3 thì không chạy được....khi em f10 thì nhận thấy mảng str không nhận giá trị . Em thực sự không hiểu...Mọi người cho em ý kiến nhé [IMG]images/smilies/biggrin.png[/IMG]
Mã:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int N, in, out, num_e;
void **table;
void fifodestroy();
int fifoempty();
int fifoput(void *next);
void fifoinit(int size);
/*init queue*/
void fifoinit(int size)
{
num_e = 0; in = 0; out = 0;
N = size;
printf("fifo init
");
table = (void**)malloc(N*sizeof(void*));
}
/*free memmory*/
void fifodestroy()
{
int i;
if (!fifoempty())
free(table);
else
{
for (i = out; i<in; i++)
{
free(table[i]);
}
free(table);
}
}
/*empty queue = 1 else 0*/
int fifoempty()
{
return(num_e == 0);
}
/*insert element*/
int fifoput(void *next)
{
if (num_e == N)
return 0;
else
{
while (num_e < N)
{
table[in] = next;
num_e++;
in = (in + 1) % N;
}
return(1);
}
}
void fifoget(void *next1)
{
while (num_e > 0)
{
next1 = table[out];
num_e--;
out = (out + 1) % N;
}
}
int main(int argc, char* argv[])
{
int y = 1;
int y1 = 0;
char *p,*q, str[64];
printf(" Give an integer for size: ");
scanf_s("%d", &y);
fifoinit(y); /*init fifo*/
do
{
putchar('
');
printf(" 0: Exit
");
printf(" 1: Insert string
");
printf(" 2: Print next string
");
printf(" 3: Output String");
fflush(stdin);
printf(" Choose one of the above options: ");
scanf_s("%d", &y1);
switch (y1)
{
case 1:
{
printf(" Insert elements
");
printf(" Give string ");
fflush(stdin);
scanf_s("%s", str);
fflush(stdin);
p = _strdup(str);
fflush(stdin);
printf(" %s", p);
if (!(fifoput((void*)p)))
{
free(p);
printf(" Table is full
");
}
else
{
printf(" Insert successful
");
}
}
case 2:
{
printf("Get elements
");
}
break;
case 3:
{
q = "";
fifoget(q);
fflush(stdin);
printf(" %s", q);
break;
}
}
} while (y1 != 0);
fifodestroy();
// exit(0);
}
Vòng tay phong thủy là một vật phẩm mang lại sự may mắn trong tài lộc, tình duyên, sự nghiệp,.. Là một vật phẩm không xa lạ gì với chúng ta, vòng tay phong thủy có nhiều màu, đa dạng và mỗi màu sắc...
Ý nghĩa và cách phân loại vòng tay...