C程序在输入大写字母时跳过行?

C程序在输入大写字母时跳过行?,c,C,因此,当我运行程序时,如果我在第一个问题中输入“是”,它会提示这是哪种经销商。只有输入非大写字母,我才能正确地运行整个程序,提示所有printf语句。例如: Yes bartow ford wash brian cox ford explorer (if i input 2001 ford explorer it skips the next two printf statements idk why) etc. etc. 但是如果我使用大写字母,比如 Bartow Ford

因此,当我运行程序时,如果我在第一个问题中输入“是”,它会提示这是哪种经销商。只有输入非大写字母,我才能正确地运行整个程序,提示所有
printf
语句。例如:

Yes  
bartow ford  
wash  
brian cox  
ford explorer (if i input 2001 ford explorer it skips the next two printf statements idk why)

etc. etc.
但是如果我使用大写字母,比如

Bartow Ford.
它跳过
printf
。它需要什么样的工作? 我知道有些语境很糟糕,但我首先担心的是结构,然后再回到过去,让语言变得“漂亮” 我的想法是允许用户输入汽车来自何处、来自何处、需要对汽车做什么、车主、制造车型等,然后输入任何其他信息。然后将其保存到我桌面上的一个单独文件中。 非常感谢你们提供的任何信息

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define WASH 20
#define WAX 30
#define FULL 100
#define MINI 40
#define TINT 60

int main() {

    int exit;

    char type[40];
    char car[40];
    char name[40];
    char work[40];
    char dealer[40];
    char comments[200];

    float total;

    FILE *elite;

    elite = fopen("/Users/BlakePatterson/Desktop/Elite Detail/Customer.txt", "w");

    printf(".\nIs this a dealer car or is this a customer car?.\n");
    scanf("%s", type);

    if (strcmp(type, "Yes") == 0) {

        printf("What is the name of the dealership?.\n");
        scanf(" %s", dealer);

        printf("What type of work needs to be done to the car?\n\n 1.Wash.\n2.Wax.\n");
        scanf("  %s", work);

        printf("Please input the name of the person handling the car.\n");
        scanf("   %s", name);

        printf("Please input the make, model, year and condition of the car upon arrival.\n");
        scanf("    %s", car);

        printf("Do you need to make any more commentd?.\n");
        scanf("     %s", comments);

        printf("Are you finished? if so press 2 if not press 1.\n");
        scanf("%d", &exit);
    }

    fprintf(elite,"%s%s%s%s%s", dealer, work, name, car, comments);
    fclose(elite);
    return 0;
}
#包括
#包括
#包括
#包括
#定义清洗20
#定义蜡30
#定义满100
#定义迷你40
#定义色调60
int main(){
int出口;
字符类型[40];
炭车[40];
字符名[40];
炭制品[40];
煤焦经销商[40];
char评论[200];
浮动总额;
档案*精英;
elite=fopen(“/Users/BlakePatterson/Desktop/elite Detail/Customer.txt”,“w”);
printf(“.\n这是经销商的车还是客户的车?\n”);
scanf(“%s”,类型);
如果(strcmp(类型,“是”)==0){
printf(“经销商的名称是什么?\n”);
scanf(“%s”,经销商);
printf(“需要对汽车进行哪种工作?\n\n 1.清洗。\n2.打蜡。\n”);
scanf(“%s”,工作);
printf(“请输入操作车辆的人员的姓名。\n”);
scanf(“%s”,名称);
printf(“请输入车辆到达时的品牌、型号、年份和状况。\n”);
scanf(“%s”,car);
printf(“您是否需要进行更多注释?\n”);
scanf(“%s”,注释);
printf(“完成了吗?如果完成了,请按2;如果没有完成,请按1。\n”);
scanf(“%d”,退出(&E);
}
fprintf(精英,“%s%s%s%s”,经销商,工作,姓名,汽车,评论);
fclose(精英);
返回0;
}

你观察到的行为与大写字母无关,而是与多个单词的答案有关。您不能用
scanf(“%s”,经销商)读取多个单词。初始空间是多余的,因为
%s
跳过任何前导空白并将单个字读入目标数组。后续调用
scanf()
将阅读以下单词作为其他问题的答案


您可以使用
fgets(经销商,经销商的大小,标准代码)
并删除尾随换行符,或者使用
scanf(“%39[^\n]”,经销商)
读取同一行中最多39字节的多个字。其他输入行也是如此,根据不同的数组大小进行调整。

在另一个单词后面有空格时,应该立即“跳过”该行<代码>%s
最多只能解析第一个空格。也许您对我的更可靠的输入感兴趣。顺便说一句,
%s
如果没有空格,将永远不会停止解析,因此它最终会溢出任何缓冲区。切勿使用
s
和其他转换为带有
scanf()
且没有明确字段宽度的字符串(在您的情况下:写入
%39s
以解析到40字节缓冲区),尽管它可能不相关,但您不应使用标识符
exit
。如何正确回答“是”“这是经销商的车还是客户的车?”在Felix Palmen。我从scanf阅读了您的初学者指南()非常感谢。唯一让我困惑的是fgets中的标准输入是什么?我将新代码设置为:printf(“经销商的名称是什么。\n”);fgets(经销商,40,标准输入);好的,我会这样做,然后在下班后重写程序。非常感谢。如果不是太多的话,我还有另一个问题。我把它放在我选择的目录下开始一个文件,但它像bartowbrianwash一样出现。我怎么能说bartow“new line”Brian“new line”呢“在正在写入的文件中清洗。此外,我非常感谢您的回复。@WatchTower:您应该了解
fprintf
。使用:
fprintf(精英,“%s\n%s\n%s\n%s\n%s\n”、经销商、工作、姓名、汽车、评论)太棒了,谢谢,伙计,我们刚开始上课。此类的作用域很可能只涉及将整数存储到外部文件中。