用microsoft visual studio 2008执行C语言出现栈溢出怎么解决?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用microsoft visual studio 2008执行C语言出现栈溢出怎么解决?相关的知识,希望对你有一定的参考价值。

源代码:
#include<stdio.h>
void main()

void hanoi(int n,char one,char two,char three);
int m;
printf("input the number of diskes:");
scanf("%d",&m);
printf("The step to moveing %d diskes:\n",m);
hanoi(m,'A','B','C');


void hanoi(int n,char one,char two,char three)

void move(char x,char y);
if(n==1)
move(one,three);
else

hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);

void move(char x,char y)

printf("%c-->%c\n",x,y);


汉诺塔程序
语法没有错误
可是输入 disk碟子数后出现
unhandled exception at 0x010114b9 in project 3exe:0xc00000FD:Stack overflow.怎么办?为什么会栈溢出?就算我输入1也会溢出,为什么?
用Turbo C++3.0执行就没有问题,为什么????

if(n==1)
move(one,three);
else

hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);

应该是这样的
if(n==1)
move(one,three);
else

hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);

大括号位置打错了,呵呵,要用心检查哦!
参考技术A 程序有错误,我在vc++6.0编译器编译后,运行只有这样就没了。
C:\cl6>test
input the number of diskes:10
The step to moveing 10 diskes:
A-->B

C:\cl6>

用\Microsoft Visual Studio 2010编C++程序,运行时程序报错

我装的是2010的,开了新的文件,我选的是C++里的第一个,就是Win32控制台应用程序。之后写入了代码
#include<iostream>
#include<string.h>
#include<fstream>
#include<cmath>
#define PI 3.1415926
#define G 9.81

using namespace std;
class Parabola

private:
double V,ang,high;
double Vx,Vy,Sx,Sy,t;
public:
Parabola(const double v1,const double an,const double h);
double Get_Vy();
double Get_Sx();
double Get_Sy();
;
Parabola::Parabola(const double v1,const double an,const double h)

V=v1;ang=an;high=h;
Vx=cos(PI*ang/180)*V;
Vy=sin(PI*ang/180)*V;
Sx=0;Sy=high;t=0.1;

double Parabola::Get_Sx()

Sx+=Vx*t;
return Sx;

double Parabola::Get_Vy()

Vy-=G*t;
return Vy;

double Parabola::Get_Sy()

Sy+=Vy*t;
return Sy;

const char *file="parabola.txt";
int main(void)

double v,ang,h,t;
char ch,buffer[100];
int selection,lengh;
cout<<"1.Read\n2.Write\n3.quit\n";
while(cin>>selection&&selection!=3)

if(selection>3||selection<1)
cout<<"No Such Selction\n";
else if(selection==1)

cout<<"Input the name of file to be opened:";
cin>>buffer;
lengh=strlen(buffer);
char *fname=new char[lengh];
strcpy(fname,buffer);
strcat(fname,".txt");
fstream fin(fname,ios_base::in);
if(fin.is_open())
while(fin.get(ch))
cout<<ch;
else
cout<<"No Such File\n";
fin.close();

else if(selection==2)

cout<<"input the V:";
cin>>v;
cout<<"input the angle:";
cin>>ang;
cout<<"input the high:";
cin>>h;
Parabola p(v,ang,h);
ofstream fout(file,ios_base::out);
if(fout.is_open())

fout<<"v="<<v<<",";
fout<<"angle="<<ang<<",";
fout<<"high="<<h<<endl;
for(t=0.1;t<2.1;t+=2.1)

fout<<"t="<<t<<",";
fout<<"Vy="<<p.Get_Vy()<<",";
fout<<"Sx="<<p.Get_Sx()<<",";
fout<<"Sy="<<p.Get_Sy()<<endl;


else
cout<<"Cant create file\n";
fout.close();
cout<<"Input the name of file to be saved;";
cin>>buffer;
lengh=strlen(buffer);
char *name=new char[lengh];
strcpy(name,buffer);
strcat(name,".txt");
ofstream out(name,ios_base::out);
if(out.is_open())

ifstream in(file,ios_base::in);
if(in.is_open())

while(in.get(ch))
out<<ch;

in.close();

else
cout<<"Can't Create Such File\n";
out.close();

cout<<"1.Read\n2.Write\n3.quit\n";


这个代码是计算多次叠加的X方向上的速度和位移,Y方向上的速度和位移。是一个斜抛的程序。代码里什么错误都没有报出,没有红线,但当我运行的时候包括用CTRL+F5我都试过了。但还是有错,错误提示是

无法启动程序“C:\Users\AlienS\Documents\Visual Studio 2010\Projects\Projectile program\Debug\Projectile program.exe
系统找不到指定文件

为什么会这样?代码没有错也会这样吗?怎么解决?求高手帮忙

参考技术A 到那个目录去找一下有没有编译出文件啊? 没有要编译一下的

以上是关于用microsoft visual studio 2008执行C语言出现栈溢出怎么解决?的主要内容,如果未能解决你的问题,请参考以下文章

microsoft visual studio创建button背景颜色代码

microsoft visual studio软件怎样把游戏导出来

Microsoft visual c++弹窗?

用Microsoft Visual Studio 2019写MFC程序(Bresenham画直线为例)

用\Microsoft Visual Studio 2010编C++程序,运行时程序报错

用Microsoft Visual Studio 2010编译下面这个程序总是提示Debug Assertion Failed