获得输入从功能结构 [英] getting input for structure from function
本文介绍了获得输入从功能结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是想这样的结构,主要发送给一个函数,并填写结构与功能的正确值,然后显示值,但它不是不工作,当我运行它。(我不能使用指针函数)。
结构库存{
焦炭名[20];
INT编号; };
void函数(结构存货项目);
诠释的main()
{
INT X,Y,Z;
结构库存物品;
功能(项目);
的printf(\\南主\\ n);
的printf(\\ n%S \\ T,(项目)。名称);
的printf(%I \\ T,(项目).number);
残培(); }
void函数(结构库存物品)
{
的printf(请输入项目名称\\ n);
scanf函数(%S,及(项目)。名称);
的printf(请输入项目\\ n的数量);
scanf函数(%i的,及(项目).number);
}
(即:不准我用教鞭功能)我怎样才能显示的名称,没有指针的数量。
解决方案
库存结构
{
焦炭名[20];
INT编号;
};库存结构功能();诠释的main()
{
INT X,Y,Z;
结构库存物品;
项目=()函数;
的printf(\\南主\\ n);
的printf(\\ n%S \\ T,(项目)。名称);
的printf(%d个\\ t的,(项目).number);
残培();
}库存结构功能()
{
结构库存物品;
的printf(请输入项目名称\\ n);
scanf函数(%S,&安培; items.name);
的printf(请输入项目\\ n的数量);
scanf函数(%d个,&安培; items.number);
返回的物品;
}
I was trying to send a structure to a function and fill out the structure with the right value in the function and then display the value in main, but it was not is not working when i run it.(i cant use pointer functions).
struct inventory{
char name[20];
int number;
};
void function(struct inventory items);
int main()
{
int x,y,z;
struct inventory items;
function(items);
printf("\nam in main\n");
printf("\n%s\t",(items).name);
printf(" %i\t",(items).number);
getch();
}
void function(struct inventory items)
{
printf(" enter the item name\n ");
scanf(" %s ",&(items).name );
printf(" enter the number of items\n ");
scanf("%i",&(items).number );
}
(ie: i am not allowed to use pointer function ) how can i display the name and the number without pointer.
解决方案
struct inventory
{
char name[20];
int number;
};
struct inventory function();
int main()
{
int x,y,z;
struct inventory items;
items=function();
printf("\nam in main\n");
printf("\n%s\t",(items).name);
printf(" %d\t",(items).number);
getch();
}
struct inventory function()
{
struct inventory items;
printf(" enter the item name\n ");
scanf(" %s ",&items.name );
printf(" enter the number of items\n ");
scanf("%d",&items.number );
return items;
}
这篇关于获得输入从功能结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文