void WINAPI Producer(LPTSTR data[])//LPSTR data are the command line arguments, the first argument is the name of the file to be read in
{
char c1;
char c2;
char *filename = NULL;
FILE *file;
filename = data[1];//name of the file is Text1.txt
file = fopen(filename, "r");
if (file != NULL)
{
while (file != EOF)
{
fseek(file,0, SEEK_SET);
c1 = fgetc(file);//c1 is getting garbage
printf("%c", c1);//first letter should be E
c2 = fgetc(file);//c2 is getting garbage
printf("%c", c2);//second letter should be N
//the word in the file is encrypt
if (c2 == NULL)
{
c2 = " ";
}
WaitForSingleObject(openspots, INFINITE);
my_house[back].name[0] = c1;
my_house[back].name[1] = c2;
my_house[back].location++;
if (back == 9)
{
back = 0;
}
else
{
back++;
}
WaitForSingleObject(Inthewarehouse, INFINITE);
count++;
ReleaseSemaphore(Inthewarehouse,1,0);
ReleaseSemaphore(filledspots, 1, &previous_count_filled);
}
producer = FALSE;
}
}
}
我不明白。输入文件包含单词“ encrypt”,但它正在读取垃圾值。我认为fgetc有问题吗?有人可以帮我吗?