我有一个程序是为了采取命令第一个问题是格式的命令将在命令行或文件通过键入c或f 如果都没有输入while循环重复,而不允许输入等于不正确输入中的字符数,而不是停止并允许scanf再次获取输入。我不会在任何时候使用它的返回值,所以我为什么会发生这种情况而感到不知所措。正确输入'f'或'c'不会导致问题。 任何帮助,将不胜感激while循环重复scanf等于读取的字符数
#include<stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0
typedef int bool;
double **temp_array;
double temp1d_array[36];
char consolep[100];
char *fp1;
FILE *fp;
char string_IO1[50];
char string_temp[50];
char buffer[50];
char current_command[10];
int halt = 0;
char *strtodptr;
void main(){
printf("welcome \n");
char IO;
char read[250];
char file_console;
int IO_method = 0;
char command[10];
char type_IO;
char type_of_var_IO;
char dim_IO[3];
char array_string_IO[40];
//console or file
//decide IO Method loop 1
while (IO_method==0)
{
printf("please type 'c'for console or 'f' for file to select input type\n");
scanf("%c", &file_console);
//if console
if(file_console =='c')
{
IO_method=1;
printf("method is console\n");
}
//if file
else if(file_console=='f')
{
IO_method=2;
printf("method is file\n");
printf("please enter a file directory\n");
scanf("%s",&string_IO1);
}
else
{
printf("invalid entry\n");
file_console=NULL;
IO_method=0;
}
}}//code here continues but i compiled it without and has no bearing on the error.
只适用于1个字符错误答案输入“ccccc”仍然导致重复 –
发布代码不会编译 –
固定代码编译,忘记了我的导入 –