首页 > 解决方案 > 我需要帮助获取数据以显示在发票和文本文件中

问题描述

我的目标是能够收集订单号、客户名称、木材类型、字符数、字符颜色和相应的费用。在显示名称时,我不断收到错误 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。

标签: c

解决方案


推荐阅读