简答的输入输出问题求解
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的值打印不出来
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);
} printf("%d %d ",head->high,head->wide,a);有点小问题吧 22.printf("%d %d ",head->high,head->wide,a);多了个a吧
页:
[1]