while (scanf("%s", s) == 1) {

for (i = x = y =n_y= 0; s[i]; i++){
printf("%s\n", s);

if (!(p = strchr(r, s[i]))) {

break ; }
この部分でfscanでEXITが入ると終了したいんですが。