菜鸟求助C语言问题

来源:百度知道 编辑:UC知道 时间:2024/09/25 22:25:38
#include <stdio.h>
#include <stdlib.h>
#define N 1024
void string(char array[N])
{
int i,m=0,n;
char buffer[N];
printf("Enter the value of n:");
scanf("%d",&n);
printf("Enter the digit:");
for(i=0;i<n;i++)
{
scanf("%c",&buffer[i]);
}
for(i=0;i<n;i++)
{
array[m]=buffer[i];
m=m+2;
}
for(i=1;i<m-2;)
{
array[i]=' ';
i=i+2;
}
array[m-1]='\0';
}
int main()
{
char array[N];
string(array);
printf("%s",array);
system("pause");
}
去掉这2行
printf("Enter the value of n:");
scanf("%d",&n);
并将n直接赋值5 程序意思就是输入5个字符 每字符中间再插一空格 再输出 这样在Dev_c++上运行成功
我想不去掉这2行,直接从

别光给代码,不给问题啊! 至少要描述一下你的代码大致是做什么的。

#include <stdio.h>
#include <stdlib.h>
#define N 1024
void string(char array[N]) /* 这里的N多余 */
{
int i,m=0,n;
char buffer[N];
printf("Enter the value of n:");

printf("Enter the digit:"); /* 顺序错了 */
scanf("%d",&n);

for(i=0;i<n;i++)
{
scanf("%c",&buffer[i]);
}
for(i=0;i<n;i++)
{
array[m]=buffer[i];
m=m+2;
}
for(i=1;i<m-2;)
{
array[i]=' ';
i=i+2;
}
array[m-1]='\0';
}
int main()
{
char array[N];
string(array);
printf("%s",array);
system("pause");
}