why does my code have an infinite loop?
#include <stdio.h>
#include <stdlib.h>

/*
 * Write a small program that takes 1 standard inputs, a phone number and repeatedly asks for a a number
 * the program will stop asking for an input when standard input stream is closed
 * if the number is between 0 and 9 print the corresponding index
 * if the number is -1 print the whole number
 * if the number is less then -1 or greater then 9 print error and return 1
 */

int checkNum(char phone[], int num){
        if (num < -1 || num > 9){
                printf("ERROR\n");
                return 1;

}
        if (num == -1){
                for (int i = 0; i < 10; i++) {
                        printf("%c", phone[i]);
}
                printf("\n");
		return 0;
}
        else {
                for (int i = 0; i < 10; i++) {
                        if (i == num){
                                printf("%c\n", phone[i]);
				
}
}
	return 0;
}

}


int main() {
        char phone[11];
        int num = 0;
	int funcRes = 0;
	
        int res = scanf("%s %d", phone, &num);
	
	funcRes = checkNum(phone, num);

	if (funcRes == 1){
		return 1;
}

while(res != EOF){
	scanf("%d", &num);
	        
	if (res == EOF){
	break;	
}

	funcRes = checkNum(phone, num);
	
	if (funcRes == 1){
		return 1;
}	

	        
}
	return 0;
}

