eclipseテストC++プログラム01-scanf構造体入力浮動小数点数、浮動小数点数の表示
2106 ワード
//============================================================================
// Name : Test02.cpp
// Author : peterli
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdio.h>
#include <stdlib.h>
struct circuit
{
char yjtype;
int number;
int startnode;
int endnode;
int control;
double argument;
};
//
void flush()
{
char temp;
while((temp = getchar()) != '
' && temp != EOF);
}
int main() {
int numNode = 0;
int i = 0;
double tempDouble = 0.0l;
printf("please input the number of node:
numNode =");
_flushall();
scanf("%d",&numNode);
struct circuit* node = (struct circuit*)calloc(numNode,sizeof(struct circuit));
for(i = 0; i < numNode; i++)
{
printf("the %dth Node
",i+1);
_flushall();
printf("Node.yjtype: ");
_flushall();
scanf("%c",&node[i].yjtype);
printf("Node.number: ");
_flushall();
scanf("%d",&node[i].number);
printf("Node.startnode: ");
_flushall();
scanf("%d",&node[i].startnode);
printf("Node.endnode: ");
_flushall();
scanf("%d",&node[i].endnode);
printf("Node.control: ");
_flushall();
scanf("%d",&node[i].control);
printf("Node.argument: ");
_flushall();
scanf("%lf",&node[i].argument);
//scanf("%lf",&tempDouble);
//node[i].argument = tempDouble;
}
for(i = 0; i < numNode; i++)
{
printf("
the %dth Node
",i+1);
printf("Node.yjtype:%c
",node[i].yjtype);
printf("Node.number:%d
",node[i].number);
printf("Node.startnode:%d
",node[i].startnode);
printf("Node.endnode:%d
",node[i].endnode);
printf("Node.control:%d
",node[i].control);
printf("Node.argument:%f
",node[i].argument);
_flushall();
}
return 0;
}