这是我的 C 代码,它工作正常,我试图让它与 IO 重定向一起工作但失败了,无法理解这里错误的原因,我制作了测试文件 test1.in,我正在等待输出test1.out 但运行后 test1.out 为空 `
#include <stdio.h>
#define MAX_STR_SIZE 80
/*******************************************************/
int my_strcmp(char[], char[]);
int my_strncmp(char[], char[], unsigned int);
int my_strchr(char[], int);
/*******************************************************/
int main(){
int test = 0, running = 1;
char str1[MAX_STR_SIZE];
char str2[MAX_STR_SIZE];
char c;
int count;
printf("\nLet's start testing!");
while(running){
printf("\n Enter 1: to test my_strcmp(), 2: to test my_strncmp(), 3: to test my_strchr()");
scanf("%d",&test);
switch(test){
case 1: /*my_strcmp test*/
printf("\n***my_strcmp*** TEST");
printf("\nEnter first string: ");
scanf("%s",str1);
printf("Enter second string: ");
scanf("%s",str2);
printf("\nThe result is: %d\n",my_strcmp(str1, str2));
break;
case 2: /*my_strncmp test*/
printf("\n***my_strncmp*** TEST");
printf("\nEnter first string: ");
scanf("%s",str1);
printf("Enter second string: ");
scanf("%s",str2);
printf("Enter maximal number of bytes to compare: ");
scanf("%d",&count);
printf("\nThe result is: %d\n",my_strncmp(str1, str2, count));
break;
case 3: /*my_strchr test*/
printf("\n***my_strchr*** TEST");
printf("\nEnter string to search into: ");
scanf("%s",str1);
printf("Enter character to find: ");
scanf(" %c", &c);
printf("\nThe result is: %d\n",my_strchr(str1, c));
break;
default: /*bad test flag*/
printf("\nERROR: Entered number is not one of those: 1,2,3 while test is running\n");
break;
}
printf("Should we continue? 0 to exit, 1 to continue");
scanf("%d", &running);
}
return 0;
}
`