eclipse测试C++程序01-scanf结构体输入浮点数、浮点数的表示

//============================================================================
// 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()) != '\n' && temp != EOF);


}
int main() {

	int numNode = 0;
	int i = 0;
	double tempDouble = 0.0l;
	printf("please input the number of node:\nnumNode =");
	_flushall();
	scanf("%d",&numNode);
	struct circuit* node = (struct circuit*)calloc(numNode,sizeof(struct circuit));
	for(i = 0; i < numNode; i++)
	{
		printf("the %dth Node\n",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("\nthe %dth Node\n",i+1);
			printf("Node.yjtype:%c\n ",node[i].yjtype);

			printf("Node.number:%d\n",node[i].number);

			printf("Node.startnode:%d\n",node[i].startnode);

			printf("Node.endnode:%d\n",node[i].endnode);

			printf("Node.control:%d\n",node[i].control);

			printf("Node.argument:%f\n",node[i].argument);
			_flushall();
		}
	return 0;
}

转载于:https://my.oschina.net/u/185531/blog/122854

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值