scanf把空格当成字符读入变量了,想问一下怎么修改

int  Input_data(struct GOODS goods[], int nInputtedNum) {

	int result;
	while (1) {
		//提示语句放到循环内,可能更好一些。
		printf("请输入数据(END结束入库),格式如下\n");
		printf("货物名 同类产品的数量 价格\n");

		//scanf的返回值警告,可自行决定
		scanf("%s,%d,%f", &goods[nInputtedNum].name, &goods[nInputtedNum].num, &goods[nInputtedNum].price);

		//如果用户在一行的开始输入了END,则表示用户要结束入库操作
		if (!strcmp("END", goods[nInputtedNum].name))
			break;

		//以下为处理scanf返回值的例子:即未成功输入一个数,则结束输入
		if (1 != scanf("%f", &goods[nInputtedNum].price))
			break;

		nInputtedNum++; //已完成一数据输入,库存数+1
	}
	return nInputtedNum;
}

这是输入数据的代码

void Print_data(struct GOODS goods[], int nInputtedNum) {
	//打印库存列表
	//可以自已写一个打印表头的语句
	for (int i = 0; i < nInputtedNum; i++) {
		//如何让打印的内容对齐,可自己思考??
		printf("%-5s %-5d %.3f\n", goods[i].name, goods[i].num,goods[i].price );
	}

	printf("Press any key to continue...\n");
	char ch = _getch(); //仅仅是屏幕暂停,此输入值无其它使用价值
	return;
}

这个是读取输入数据的代码.

想问一下哪里错误了,为什么程序总是把空格当成赋值给变量num,出现这种情况需要怎样更改呢?

&goods[nInputtedNum].name

name应该是个char数组,不需要加&

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <conio.h>  //_getch()在此头文件中
#include <stdlib.h> //system()函数在此头文件
#include <string.h> //strcmp()函数在此头文件中

struct GOODS {
	int num1;//货物号
	char name[21];//货物名
	
	int num2;//同类产品的数量   
	float price;

}; 

//入库
int  Input_data(struct GOODS goods[], int nInputtedNum);
//打印清单
void Print_data(struct GOODS goods[], int nInputtedNum);
//统计分析
void Stat_data(struct GOODS goods[], int nInputtedNum);
//
//以下函数的定义没有顺序要求
int main()
{
	struct GOODS goods[50]; //假设最大可存储200条
	int nInputtedNum = 0; //已入库的商品数量

	//4 菜单驱动程序流程程序
	while (1) {
		system("cls");  

		printf("1. 清点入库\n\n");
		printf("2. 打印库存\n\n");
		printf("3. 统计库存总价值\n\n");
		printf("0. exit\n\n");

		printf("请输入功能选项\n\n");
		char ch = _getch(); //用于读用户的选项,且此函数不产生回显

		if (ch == '0')
			break;  //退出程序


		system("cls"); 

		switch (ch) {
		case '1':
			//float  ave_col(struct STUDENT[]);//语法上是正确
			nInputtedNum = Input_data(goods, nInputtedNum);
			break;
		case '2':
			Print_data(goods, nInputtedNum);
			break;
		case '3':
			Stat_data(goods, nInputtedNum);
			break;
		}
	}

	return 0;
}
int  Input_data(struct GOODS goods[], int nInputtedNum) {

	int result;
	while (1) {
		//提示语句放到循环内,可能更好一些。
		printf("请输入数据(END结束入库),格式如下\n");
		printf("货物号 货物名 同类产品的数量 价格 \n");
		//scanf的返回值警告,可自行决定
		scanf("%s",//%d,%s,%d,%f
			//goods[nInputtedNum].num1,
			goods[nInputtedNum].name
			//goods[nInputtedNum].num2,
			//goods[nInputtedNum].price
		);// %d %s %s	goods[nInputtedNum].factory,goods[nInputtedNum].produce,goods[nInputtedNum].date
	
		//如果用户在一行的开始输入了END,则表示用户要结束入库操作
		if (!strcmp("END", goods[nInputtedNum].name))
			break;

		//以下为处理scanf返回值的例子:即未成功输入一个数,则结束输入
		if (1 != scanf("%f", &goods[nInputtedNum].price))
			break;

		nInputtedNum++; //已完成一数据输入,库存数+1
	}

	return nInputtedNum;
}



void Print_data(struct GOODS goods[], int nInputtedNum) {
	for (int i = 0; i < nInputtedNum; i++) {

		printf("%d %s %d %.3f",
			goods[i].num1,
			goods[i].name,
			goods[i].num2,
			goods[i].price
			);
	}
	//%s %s。goods[nInputtedNum].produce,,goods[nInputtedNum].date
	printf("Press any key to continue...\n");
	char ch = _getch(); //仅仅是屏幕暂停,此输入值无其它使用价值
	return;
}

void Stat_data(struct GOODS goods[], int nInputtedNum) {
	//完成统计并输出
	return;
}

这是完整的程序