Read redirected file from stdin in C (a.out < file)

Hello everybody,
Having a file with the following content:

192.168.0.254->192.168.0.1
192.168.0.2->192.168.0.34
192.168.0.56->192.168.0.77

I need to code a program in C to read it from stdin redirection (i.e. root@box~# ./a.out < file), my question is, how can i do that?

I've tried with functions like fscanf(stdin, "%s->%s", var1, var2), but it only reads the first line of the file. How do i pass to the next line in file, and how do i detect the EOF?

Thanks in advance!

are you sure you get an output?
the < already open stdin on file,no need to do more to redirection.However,"-->" is NOT a seperator for scanf,you can achieve your goal by this:

int main()
{	
	char line[BUFSIZ];
	char *tok;

	while(fgets(line,BUFSIZ,stdin) != NULL){
		for(tok=strtok(line,"-->");tok != NULL;tok=strtok(NULL,"-->")){
			printf("%s\n",tok);
		}
	}
}

strtok is very 70's, and scanf can do the job here. but slurping the line into a fixed-size buffer, for robustness, can still work:

#include <stdio.h>
int main() {
    char line[BUFSIZ],a[BUFSIZ],b[BUFSIZ];
    while (fgets(line,sizeof(line),stdin) &&
           sscanf(line,"%[0-9.]->%[0-9.] ",a,b) == 2) {
        printf("a(%s) b(%s)\n",a,b);
    }
    return 0;
}