消防安全逃生小知识:代码代码为什么为什么不能运行,能编译。

来源:百度文库 编辑:中科新闻网 时间:2024/05/04 06:43:24
#include<stdio.h>
void main(int argc,char *argv[])
{int n,i=0;
while(argv[1][i]!='\0')
{n=fun();i++;}
printf("%d\n",n*argc);
}
int fun()
{static int s=0;
s+=1;
return s;
}

#include<stdio.h>

int fun()
{static int s=0;
s+=1;
return s;
}

void main(int argc,char *argv[])
{
int n,i=0;
while(argv[1][i]!='\0')
{n=fun();i++;}
printf("%d\n",n*argc);
}

要把fun的定义放到前面去,或者声明
主函数要传参数才行,不然运行肯定要报错的,你可以穿参数,也可以把argc argv在主函数中读入

#include<stdio.h>
void main(int argc,char *argv[])
{int n,i=0;
while(argv[1][i]!='\0')
{n=fun();i++;}
printf("%d\n",n*argc);
}
printf("-----------------");
int fun()
{static int s=0;
s+=1;
return s;
}
也许你可以这样试一下,也许已经运行了也说不定

可以运行啊?还没听说过什么程序不能运行,顶多是运行出错。
但这段代码不出错。你可以调试一下啊?另外能编译过么?应该把方法func放在MAIN上面,或者写个函数声明啊。
运行的时候要跟参数。如果没有参数取argv[1]会出问题。
(或者代码里判断一下,没有参数就返回就行了。)