编码程序分割错误
segmentation fault with encoding program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char* argv[])
{
int n;
FILE *f1;
char fn[]={"test.txt"};
int c;
f1=fopen(fn,"r");
c=fgetc(f1);
while(c!=EOF){
if ((c<'Z')&&(c>'A')) c=c+n;
}
fputc(c,f1);
fclose(f1);
}
我正试图写一个程序编码(!?我不知道是不是这么叫的,因为英语是我的第二语言)。如果我输入的步骤数为4,它应该改变A为E, B为F,等等。但一直显示"分段故障(堆芯)"。我不知道怎么了,请帮帮我。
我在你的代码中发现了这些问题:
-
n
未在程序中初始化 -
r
是只读模式,为了写,你必须使用w+
或r+
-
fputc( int c, FILE *fp );
该功能可用于对文件进行写操作。它返回成功时写入的字符,如果有错误则返回EOF。 -
分割错误是由于在文件程序中使用
r
模式,请尝试使用w+
模式运行程序。
相关文章:
- C++映射分割错误(核心转储)
- 由cin中的字符串中未捕获空白引起的分割错误
- 删除映射和分割错误中的一个过去结束元素
- 在指向函数中读取变量时出现分割错误
- 在链表中的第 n 位插入显示分割错误
- 较高值 n 的分割错误(例如 n=999997)
- 尝试通过memcpy复制大尺寸浮点向量时的分割错误
- 分割错误:向量中的擦除功能
- 向量向量的分割错误
- 我在C++中编写了一个方法来打印树类的预序,但它显示了分割错误
- C ++分割错误,为什么使用"long long"我没有得到答案?
- 在尝试使用递归查找集合子集的总数时,我遇到了分割错误
- 分割错误 11:尝试使用 cin 输入 B[1] 时
- 集合布局上的 Qt 分割错误
- 高达20亿的筛子会产生分割错误
- G :内部编译器错误:分割故障(程序CC1PLUS) - 我在哪里开始
- 二进制搜索树操作程序错误:分割故障(核心倾倒)
- 在给出正确的输出后,给出错误分割错误(核心转储)
- 得到错误分割错误(核心转储)进程返回139 (0x8B)
- 内部编译错误:分割错误在gcc.发送可变模板到struct时