智能 发表于 2013-10-10 21:46:42

简答的输入输出问题求解

include<stdio.h>
#include<stdlib.h>
typedef struct Waterdate
{
long long high;
long long wide;
struct Waterdate * next;
} WATER;

int main()
{
int n,i,a;
scanf("%d",&n);
WATER * head;
head=(WATER *)malloc(sizeof(WATER));

for(i=0;i<n;i++)
{
head->next=(WATER * )malloc(sizeof(WATER));
head=head->next;
a=scanf("%d %d",&(head->high),&(head->wide));
printf("%d %d ",head->high,head->wide,a);
}
head->next=NULL;
system("pause");
return(0);
}问题
1,:a不是应该返回scanf读取成功的数据个数吗,为什么打印不出来
2,:为什么 head->wide的值打印不出来

tsembrace 发表于 2013-10-10 23:28:20

include<stdio.h>   //少了"#"
#include<stdlib.h>
typedef struct Waterdate
{
long long high;
long long wide;
struct Waterdate * next;
} WATER;

int main()
{
int n,i,a;
scanf("%d",&n);
WATER * head;          //变量定义摆在代码块最前面去,和上面那句scanf交换下位置
head=(WATER *)malloc(sizeof(WATER));

for(i=0;i<n;i++)
{
head->next=(WATER * )malloc(sizeof(WATER));
head=head->next;
a=scanf("%d %d",&(head->high),&(head->wide));   
printf("%d %d ",head->high,head->wide,a);         //格式符漏了个%d
}
head->next=NULL;
system("pause");
return(0);
}

夏七夕 发表于 2013-10-12 11:42:18

printf("%d %d ",head->high,head->wide,a);有点小问题吧

随风听雨雪 发表于 2013-10-15 12:13:38

22.printf("%d %d ",head->high,head->wide,a);多了个a吧
页: [1]
查看完整版本: 简答的输入输出问题求解