C语言 数组分割数问题

[复制链接]
查看11 | 回复6 | 2011-5-15 03:23:53 | 显示全部楼层 |阅读模式
对C语言比较感兴趣,预习了一些,然后遇到如题目的题。程序可以运行,但无法执行。求教:
#includestdio.h
#includestdlib.h
intmain()
{
inti,n;
ints[n];
scanf(\"%s\",s);
for(i=0;i=n;i)
printf(\"%s\",s);
system(\"pause\");
return0;
}
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
分析下你的错误
#includestdio.h
#includestdlib.h

intmain()
{
inti,n;
ints[n];//定义数组时,不能对数组的大小即n做动态定义
scanf(\"%s\",s);
for(i=0;i=n;i)//这里i不一定=n;而是依靠strlen(s)来决定的
printf(\"%s\",s);//这里是字符的形式输出,\"%s\"是按照字符串形式输出的意思,应该是%c
system(\"pause\");
return0;
}









<h4class=\"ask\">追问


那将N改成空格吗?这样的话还是不行啊
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
不是空格,是一个具体的数,如10
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
不是很清楚,请问修改后的代码是怎样的?
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
#includestdio.h
#includestdlib.h
#defineMAX100
intmain()
{
inti=0,n=MAX;
intch;
chars[n];
while((ch=getchar())!=\'\\n\'){
s=ch;

}
s=\'\\0\';
printf(\'\\n\');
printf(\"%s\",s);
system(\"pause\");
return0;
}


不知道你是不是这意思。
后面那个for(i=0;i=n;i)
是输出n次结果。我以为是数组的上界,不知道我理解对不对。因为输出N次结果没什么意义吧。
还有我不懂啥叫数组分割,所以很纠结。。。
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
按你这么改的话:#includestdlib.h
#includestdio.h
intmain()
{
inti,n,len;
chars[99];
scanf(\"%s\",s);
len=strlen(s);//在这里提示出错,将strlen改成char也同样不行
for(i=0;ilen;i)
printf(\"%c\",s);
system(\"pause\");
return0;
}
回复

使用道具 举报

千问 | 2011-5-15 03:23:53 | 显示全部楼层
你用的什么软件?我用vc6就没有问题。。。可以运行。
那你可以再加一个头文件“#includestring.h”试试。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行