首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

segement fault!

2012-03-22 
求助segement fault!!!C/C++ code#include stdio.h#include stdlib.hint gcd(int a,int b){while(a!b

求助 segement fault!!!

C/C++ code
#include <stdio.h>#include <stdlib.h>int gcd(int a,int b){    while(a!=b)    {        if(a>b)        a-=b;        else        b-=a;    }    return a;}void juggling (int i,int n,char *x){    int cycles=gcd(i,n);    int t;    for(int j=0;j<cycles;j++)    {        t=x[j];        int k=j;        do        {            x[k%n]=x[(k+i)%n];//单步调式到这里。。。。显示堆栈错误?               k+=i;        }while(k%n!=j);        x[(k-i)%n]=t;    }}int main(){    char *s="abcdefgh";    int n=8;    int i=3;    juggling(i,n,s);    puts(s);}


到注释哪行就停止了 
求高人分析原因啊!!

[解决办法]
char *s="abcdefgh";
==>
char s[]="abcdefgh";

[解决办法]
C/C++ code
char *s="abcdefgh";//这个是储存在常量区,不能被修改。。。 

热点排行