小编Nar*_*xus的帖子

C中的切换功能可以完成所有情况

好的,所以我正在为某些东西编写代码,我在测试开关功能时遇到了问题.它完成了从一个人的选择中增加的所有情况(我的解释).有人可以帮我解释一下为什么会这样吗?

#include <stdio.h>
#include <stdlib.h>
#include "ratedzfunctions.h"

int main()
{

    int selection, loop=1;
    FILE* fajl;

    //Opening the participants file
    fajl=fopen("participants.txt","r+");
    if (fajl==NULL)
    {
        printf("The file cannot be opened.\n");
    }

    //MENU
    do 
    {
        printf("\nMENU: \n------------\n1. RATEDZ\n\n2. STATISTICS\n\n3. EXIT\n\n==>");
        scanf("%d", &selection);

        switch (selection)
        {
        case 1:
            ratedz(fajl);
        case 2:
            stats(fajl);
        case 3:
            loop=0;
        }
    }

    while (loop==1);

    fclose(fajl);

    return 0;
}

//THIS IS FROM RATEDZFUNCTIONS.H

void ratedz(FILE *fajl)
{
    printf("\nTEST RATEDZ");
}

void stats(FILE *fajl)
{
    //Printing all participants
    char *buffer=(char*) malloc(50); …
Run Code Online (Sandbox Code Playgroud)

c switch-statement

1
推荐指数
2
解决办法
1280
查看次数

标签 统计

c ×1

switch-statement ×1