将文件内容从下部情况更改为大写的问题
我正在尝试使用下面的代码将文件中的内容从下层更改为上情况。它被困在一个无限的循环中。这里有什么错误?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *fp = fopen("file.txt", "r+");
if (fp == NULL)
{
printf("error occured");
exit(1);
}
char c;
while ((c = fgetc(fp)) != EOF)
{
if (islower(c))
{
fseek(fp, -1, SEEK_CUR);
fputc(toupper(c), fp);
}
//fseek(fp, 0, SEEK_CUR);
}
fclose(fp);
return 0;
}
如果未注释的行未注册,该程序就可以正常工作。
如果可能的话,请提及一些详细了解FSEEK功能的良好资源。
I am trying to change the contents in a file from lower to upper case by using the code below. It got stuck in an infinite loop. What is the mistake here?
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
FILE *fp = fopen("file.txt", "r+");
if (fp == NULL)
{
printf("error occured");
exit(1);
}
char c;
while ((c = fgetc(fp)) != EOF)
{
if (islower(c))
{
fseek(fp, -1, SEEK_CUR);
fputc(toupper(c), fp);
}
//fseek(fp, 0, SEEK_CUR);
}
fclose(fp);
return 0;
}
The programme is working fine if the commented line is uncommented.
If possible, please mention some good resource for knowing about fseek function in detail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论