c - 我需要帮助获取数据以显示在发票和文本文件中
问题描述
我的目标是能够收集订单号、客户名称、木材类型、字符数、字符颜色和相应的费用。在显示名称时,我不断收到错误 3221225477...
#include <stdio.h>
#include <stdlib.h>
#define str_size 100
int OrderNumber, WoodType, CharacterNo, CharacterColor, WoodTypeCharge, CharacterCharge, CharacterColorCharge, TotalCharges;
wchar_t* CustomerName[str_size], FamilyName;
char CharacterInput[str_size];
wchar_t* CharacterColorName, *WoodTypeName;
const int BaseCharge = 30;
int ordernum();
int customername();
int woodtype();
int characterinput();
int charactercolor();
int charactercolorname();
int errorcheck();
int main()
{
ordernum();
customername();
woodtype();
characterinput();
charactercolor();
errorcheck();
}
int ordernum()
{
printf("Please enter the order number.\n");
scanf(" %d", &OrderNumber);
return OrderNumber;
}
一切都好,直到这里。
int customername()
{
printf("Please enter the customer's first name and family name.");
//fgets( CustomerName, sizeof(CustomerName), stdin);
scanf(" %s %s",&CustomerName, &FamilyName);
return CustomerName;
}
int woodtype()
{
printf("\nPlease select the wood type to be used from the following.:\n1 - Pine\n2 - Oak (+$15)\n");
char option;
option = getch();
if (option=='1')
{
WoodType = 1;
WoodTypeName = "Pine";
printf("Pine\n");
}
else if (option=='2')
{
WoodType = 2;
WoodTypeName = "Oak";
printf("Oak\n");
}
else
{
printf("Invlid selection.\n");
return woodtype();
}
return WoodType, WoodTypeName;
}
我实际上很困惑,因为这部分代码实际上运行良好。我以几乎完全相同的结构构建了“颜色”部分,但是......
///fgets(str, sizeof(str), stdin);
int characterinput()
{
printf("\nPlease enter the number of characters to be placed on the sign.\n");
scanf(" %ld", &CharacterNo);
// fgets(CharacterInput, sizeof CharacterInput, stdin);
// int i;
// while(CharacterInput[i]!='\0')
// {
// if((CharacterInput[i]>='a' && CharacterInput[i]<='z') || (CharacterInput[i]>='A' && CharacterInput[i]<='Z' || CharacterInput[i]>='0' && CharacterInput[i]<='9'))
// {
// CharacterNo++;
// }
// }
//CharacterNo = sizeof(CharacterInput);
//scanf(" %s",&CharacterInput[30]);
//charactercounter()
//CharacterInput
return CharacterNo;
}
int charactercolor()
{
printf("\n\nPlease select the color of the characters from the following:\n1 - Black\n2 - White\n3 - Gold Leaf (+$12)\n");
char option;
option = getch();
if (option=='1')
{
CharacterColor = 1;
printf("Black\n\n");
}
else if (option=='2')
{
CharacterColor = 2;
printf("White\n\n");
}
else if (option=='3')
{
CharacterColor = 3;
printf("Gold Leaf\n\n");
}
else
{
printf("Invlid selection.\n");
return charactercolor();
}
return CharacterColor;
}
int charactercolorname()
{
if (CharacterColor == 1 )
{
CharacterColorName = "Black";
}
else if (CharacterColor == 2 )
{
CharacterColorName = "White";
}
else
{
CharacterColorName = "Gold Leaf";
}
return CharacterColorName;
}
int errorcheck()
{
if (WoodType == 2)
{
WoodTypeCharge = 15;
}
else
{
WoodTypeCharge = 0;
}
if (CharacterNo > 6)
{
int ChargeableCharacters, CharacterCharge;
ChargeableCharacters = CharacterNo - 6;
CharacterCharge = ChargeableCharacters * 3;
}
else
{
CharacterCharge = 0;
}
if (CharacterColor == 3)
{
CharacterColorCharge = 12;
}
else
{
CharacterColorCharge = 0;
}
TotalCharges = BaseCharge + WoodTypeCharge + CharacterCharge;
printf("Please confirm if the information below is accurate.\n");
printf("Order no.: %d\n", OrderNumber);
printf("Custumer name: %c %c\n", CustomerName, FamilyName);
printf("Wood used: %s\n", WoodTypeName);
// printf("To be written on sign: %s\n",CharacterInput);
printf("Total characters: %d\n", CharacterNo);
printf("Character color: %s\n", CharacterColorName);
printf("\n\n\nInvoice\n");
printf("Base charge: %d\n", BaseCharge);
printf("Wood charge: %d\n", WoodTypeCharge);
printf("Character charge: %d\n", CharacterCharge);
printf("Character color charge: %d\n", CharacterColorCharge);
printf("________________________________________________________________\n");
printf("Total charges: %d\n",TotalCharges);
return 0;
}
在发票中,将 %c %c\n", CustomerName, FamilyName 更改为 %s 会在此时停止程序并给出错误 3221225477。
解决方案
推荐阅读
- django - Django:显示数据库信息以匹配表单?ValueError: .. 没有返回 HttpResponse 对象。它返回 None 而不是
- linux - 设置 Windows Pycharm 以在我的 linux 服务器上使用 Git
- react-native - 在 React Native Web 上编译失败
- android - UI Thread 和运行 TCP Client 的 Worker 线程之间的持续数据传输
- javascript - 获取“不允许的方法:/users/update_contact/”
- laravel - 在laravel中查询相关模型表的所有内容
- javascript - Object.values 似乎不适用于枚举类型
- c# - 在没有警告的情况下从 Entity Framework Core 执行动态 SQL
- java - 关注JLS的词汇
- spacy - 如何获得用于计算 NER 模型指标的混淆矩阵?