Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 我该如何解决这个问题?它崩溃了_C_Switch Statement - Fatal编程技术网

C 我该如何解决这个问题?它崩溃了

C 我该如何解决这个问题?它崩溃了,c,switch-statement,C,Switch Statement,单个程序自行运行,但在程序运行后出现无效参数 为什么会发生这种情况。你甚至可以帮助我,告诉我在哪里可以了解到这种情况。谢谢 #include<stdio.h> #include<stdlib.h> void ld_file(); //declaring functions void mirror_file(); int main()//setting up the menu { int choice; printf("Choose a digit be

单个程序自行运行,但在程序运行后出现无效参数 为什么会发生这种情况。你甚至可以帮助我,告诉我在哪里可以了解到这种情况。谢谢

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

void ld_file(); //declaring functions
void mirror_file();

int main()//setting up the menu
{
    int choice;
    printf("Choose a digit between 0 and 5\n");
    scanf("%d", &choice);

    switch (choice)
    {
        case 0:{ld_file();
        break;}

        case 1:{mirror_file();
        break;}
    }
}
// Individual Programs
//**************Load file***********//
void ld_file()
{
    char ch, file_name[25];
    FILE *in;

    printf("Enter the file name\n");
    gets(file_name);
    in = fopen(file_name,"r"); // reading file
    if( in == NULL )
       {
           perror("File not found.\n");
           exit(EXIT_FAILURE);
        }
        printf("Contents of %s are:\n", file_name);

        while( ( ch = fgetc(in) ) != EOF )
            printf("%c",ch);
        fclose(in);
        return;
}

//*****************Copy File**************//
void mirror_file()
{
   char ch, orig_file[20], new_file[20];
   FILE *orig, *neo;

   printf("Enter name of file to copy\n");
   gets(orig_file);

   orig = fopen(orig_file, "r");

   if( orig == NULL )
   {
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }

   printf("Enter name of new file\n");
   gets(new_file);

   neo = fopen(new_file, "w+");
   fprintf(neo,"620048876, 23/4/14\n");

   if( neo == NULL )
   {
      fclose(orig);
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }

   while( ( ch = fgetc(orig) ) != EOF )
      fputc(ch, neo);

   printf("File copied successfully.\n");

   fclose(orig);
   fclose(neo);

   return;
}

//*********Encrypt File*******//
应该是

scanf("%d", &choice);
顺便说一句,你的开关盒应该检查字符。0是空字符,它不是在键盘上键入0时得到的字符

switch (choice)
{
    case '0':{ld_file();
    break;}

    case '1':{mirror_file();
    break;}

    case 'a': ; //etc..
}

您应该在scanf中选择paas地址:

scanf("%d", &choice);
您的开关代码应如下所示:

switch (choice)
    {
        case 0:{ld_file();
        break;}

        case 1:{mirror_file();
        break;}
    }

您需要将指向choice的指针而不是choice本身传递给scanf,即scanf%d,&choice;此外,由于选项为int,因此应该使用案例0而不是案例“0”fprintfneo,620048876,23/4/14\n;应在ifneo==NULL扫描%d之后,选项;->扫描%d%*c,&choice;和char ch->intch@BLUEPIXY... 它现在运行,但当我选择与程序对应的数字时,程序运行时没有实际执行它应该执行的操作。我首先自己制作了这些程序,所以我知道它应该是有效的
switch (choice)
    {
        case 0:{ld_file();
        break;}

        case 1:{mirror_file();
        break;}
    }