Я испытываю очень странное поведение при попытке напечатать содержимое текстового файла (test_input.txt) после того, как я перенаправил его на стандартный ввод этой программы main.exe, скомпилированной с помощью mingw на windows 10. Она напечатает хорошо, если я создаю целое число до того, как l oop, но ничего другого.
test_input.txt:
2
3
5 1 2
6
1 3 3 2 2 15
main. c, который ничего не печатает:
#include <stdio.h>
#include <string.h>
#define MAXTESTS 100
#define MAXPAPERS 10000
int main(){
char*ptr;
while(fgets(ptr,MAXPAPERS*2,stdin)){
printf("%s",ptr);
}
return 0;
}
вывод:
C:\temp>gcc -o main.exe main.c
C:\temp>main.exe < test_input.txt
C:\temp>
основной. c, который печатает:
#include <stdio.h>
#include <string.h>
#define MAXTESTS 100
#define MAXPAPERS 10000
int main(){
char*ptr;
int whatever = 0;
while(fgets(ptr,MAXPAPERS*2,stdin)){
printf("%s",ptr);
}
return 0;
}
вывод:
C:\temp>gcc -o main.exe main.c
C:\temp>main.exe < test_input.txt
2
3
5 1 2
6
1 3 3 2 2 15
C:\temp>