Program received signal SIGSEGV, Segmentation fault.是什么地方发生问题了?

sinat_37043863 2016-12-14 10:29:04
小弟刚开始学习c语言,顺着cs50的课程一点一点的学习,现在有个程序出现了问题。我用gdb检查了之后发现报错
Program received signal SIGSEGV, Segmentation fault.
0x76d7b332 in vswprintf () from C:\WINDOWS\SysWoW64\msvcrt.dll
。麻烦大家给看看。谢谢,程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int
main (int argc, char *argv[])
{
char y = 'a';
int j = 0;
int i = 0;
char x[10];
while((int)y != 121)
{
printf("\ninput the decode key word in big letter:");
scanf("%s",&x);
printf("\nthe key word is %s , if it is right input y, if you want to input another key work print any other key: ", x);
fflush(stdin);
scanf("%c",&y);
for(int a = 0;a < strlen(x); a++)
{
if ((int)x[a] < 65 || (int)x[a] > 90)
{
printf("please input the correct word!");
y = 'a';
break;
}
}
}
char z[150];
int n[50];
int c = 0;
int b = 0;
int d = 1;
int f = 0;
int g = 0;
while(d != 0) 从这里开始出现问题了
{
printf("\ninput the sentence you want to transcode: ");
fflush(stdin);
gets(z);
if(strlen(z)%3 == 0)
{
while(b < strlen(z))
{
n[c] = ((int)z[b]-48)*100 + ((int)z[b+1]-48)*10 + ((int)z[b+2]-48);
c++;
b = b + 3;
printf("%c",z[b]);
}
d = 0;
}
else
printf("\nplease in put the correct password.");
}
/*printf("well done and %d and %d",n[1],n[9]);*/
while(i < strlen(z)/3)
{
if ( j == strlen(x) )
{
j = j - strlen(x);
}
z[i] =(char) (n[i] - (int) x[j] + 91);
printf("%s",z[i]);
i++;
j++;
}
int q = 0;
while(q != 13)
{
printf("\npress enter to quit the program");
fflush(stdin);
q = getch();
}

}
程序的主要思想是用户输入我之前一个小程序得到的密码,每3个数能转化成一个字母
...全文
460 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-12-15
  • 打赏
  • 举报
回复
printf里面的%和变量的一一对应关系 scanf里面的%和变量以及变量前加不加&的一一对应关系 是C代码中非常容易出错的地方,而且通常编译还不出错。 所以在编译源代码之前值得专门仔细检查一遍甚至多遍。
AlbertS 2016-12-15
  • 打赏
  • 举报
回复
引用 1 楼 paschen 的回复:
printf("%s",z[i]); %s需要的参数类型是char*指针 而你提供的z[i] 类型是char
赞一个,这个写程序会把,z[i]当成一个地址值,然后去找个位置找字符串,但是这个地址如果是非法的,就会出现崩溃的问题
paschen 2016-12-14
  • 打赏
  • 举报
回复
printf("%s",z[i]); %s需要的参数类型是char*指针 而你提供的z[i] 类型是char

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧