
请问这个c语言程序(指针)哪里出问题呢?总是运行不了。 万分感谢!
若然把char换成int,输入输出改为%d就可以,但是如下面的char就不可以,到底为什么呢?#include"stdafx.h"#include<stdio.h>#in...
若然把char 换成int,输入输出改为%d 就可以,但是如下面的char就不可以,到底为什么呢?
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *p1,i;
void *p2;
p2=malloc(5*sizeof(char));
p1=(char *)p2;
for (i=0;i<5;i++)
{
printf("please input the %dth word\n",i+1);
scanf("%s",p1+i);
}
for (i=0;i<5;i++)
{
printf("%c ",p1[i]);
}
system("pause");
} 展开
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *p1,i;
void *p2;
p2=malloc(5*sizeof(char));
p1=(char *)p2;
for (i=0;i<5;i++)
{
printf("please input the %dth word\n",i+1);
scanf("%s",p1+i);
}
for (i=0;i<5;i++)
{
printf("%c ",p1[i]);
}
system("pause");
} 展开
3个回答
展开全部
把char *p1,i;
中的i 给抽出来,改为int i;就可以了。
中的i 给抽出来,改为int i;就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只要把#include "stdafx.h"去掉也是可以正确运行的
错不在语法上。
错不在语法上。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int LEN=10;
for(i=0;i<5;i++){
p1[i]=(char*)malloc(LEN+1);//输入单词长度不能超过LEN
scanf("%s",p1[i]);
}//End of for(i=0;i<5;i++)
for(i=0;i<5;i++){
printf("%s ",p1[i]);
}//End of for(i=0;i<5;i++)
for(i=0;i<5;i++){
p1[i]=(char*)malloc(LEN+1);//输入单词长度不能超过LEN
scanf("%s",p1[i]);
}//End of for(i=0;i<5;i++)
for(i=0;i<5;i++){
printf("%s ",p1[i]);
}//End of for(i=0;i<5;i++)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询