本文介绍了当我尝试运行我的代码时,它显示编译器停止工作,任何人都可以告诉我原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
#include<stdio.h>
int main()
{
char *s[] = {
"To err is human...",
"But to really mess things up",
"One needs to know C!!"
}, rev[3][30];
int a;
for(a = 0; a <3; a++)
{
rev[a][0] = strrev(*s[a]);
printf("%s", rev[a][0]);
}
return 0;
}
我的尝试:
试图通过一些修改编译几次但没有发生任何事情
What I have tried:
Tried to compile it several times with a few modifications but nothing is happening
推荐答案
int main()
{
char *s[] = { "To err is human...",
"But to really mess things up",
"One needs to know C!!"
};
int a;
for(a = 0; a <3; a++)
{
printf(/*"%s",*/ strrev(s[a]);
}
return 0;
}
引用:
char * s [] = {
犯错误就是人......,
但真的搞砸了,
人们需要知道C !!
}
char *s[] = {
"To err is human...",
"But to really mess things up",
"One needs to know C!!"
}
您正在尝试修改只读内存。
尝试:
You are trying to modify read-only memory.
Try:
int main()
{
char s[][30] = {
"To err is human...",
"But to really mess things up",
"One needs to know C!!"
};
int a;
for(a = 0; a <3; a++)
{
printf("%s\n", strrev(s[a]));
}
return 0;
}
BTW strrev
是一个非标准功能,事实上我的系统无法使用。我用
草绘了它
BTW strrev
is a not standard function, as a matter of fact unavailable on my system. I sketched it with
char * strrev(char * s)
{
size_t len = strlen(s);
size_t n;
for (n=0; n<len/2; ++n)
{
char tmp = s[n];
s[n] = s[len-1-n];
s[len-1-n] = tmp;
}
return s;
}
这篇关于当我尝试运行我的代码时,它显示编译器停止工作,任何人都可以告诉我原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!