【发布时间】:2014-10-03 23:01:26
【问题描述】:
您好,我正在编写一个程序,它需要从文本文件中读取,并且只接收整个文件的字母。可能是这样的
你好,我叫什么名字。我正在考虑尝试编写一个程序:“name!”
我需要做的只是阅读字母,所以我的输出将是:
hellomyname 是我想写的程序名
我有这样的东西:
while (fscanf(ifp2, "%c", &file[i]) != EOF) //scans until end of file
{
for (i = 0; i < 10000; i++) //loops a possible 10000, file could possibly be that big
{
//printf("Got inside while loop [%d]\n", i); //this just lets me see the loop
if (fscanf(ifp2, "%c ", &file[i]) == 0) //im trying to see how i can ignore some data
{
fscanf(ifp2, "%c ", &file[i]); //scans in the character
}
}
}
for (i = 0; i < 10000; i++)//prints the array of characters.
{
if(file[i] == NULL)//keeps from printing uninitialized parts of array
{
break;
}
else
{
if (counter % 80 == 0) //makes it print 80 characters per line
{
printf("\n");
}
printf("%c", file[i]);//prints the character
counter++;
}
}
我知道我可以以某种方式使用 fscanf,而且我知道它应该比这简单得多。我只需要一个指向正确方向的*指针(双关语)!
【问题讨论】:
-
每次调用
fscanf都会占用另一个角色。一次读一个,然后立即检查。 -
我应该寻找什么?如果 fscanf(ifp2, "%c ", &file[i]) == ':' 然后什么都不做,应该是什么?
-
你知道你可以做到这一切,只需使用适当的配置(伪)
while fgetc { if (isalpha) fputc }循环,对吧? -
不,我将如何使用它?我以前从未这样做过。