pass_struct_pointer_to_function3.cpp

来自「How to use nested struct」· C++ 代码 · 共 52 行

CPP
52
字号
#include <stdio.h>
#include <conio.h>
#include <mem.h>

	typedef struct /* Defines the structure */
		{
			char name[20];
			int numb;
			float amt;
		}cust;

	void intcal(cust *abc);

	void main()
	{

		cust xyz,a;
		clrscr();

		/* Accepts data into the structure */
		printf("\nEnter Customer name: ");
		gets(xyz.name);

		printf("\nEnter Customer number: ");
		scanf("%d",&xyz.numb);

		printf("\nEnter Principal amount: ");
		scanf("%f", &xyz.amt);

		//a=xyz;
		//memcpy(&a,&xyz,sizeof(cust));

		intcal(&xyz); /* Passes the structure to a function */

		getch();
	}

	void intcal(cust *abc)
	{
	float si, rate = 5.5, yrs = 2.5;

		/* Computes the interest */
		si = (abc->amt * rate*yrs) / 100;

		printf ("\nThe customer name is %s",abc->name);
		printf("\nThe customer number is %d",abc->numb);
		printf("\nThe amount is %f",abc->amt);
		printf("\nThe interest is %f",si);

		return;
	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?