1 Replies - 263 Views - Last Post: 20 April 2013 - 04:24 AM Rate Topic: -----

#1 gwnabaprmr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 08-August 08

Compare data from a txt file and an input.

Posted 20 April 2013 - 02:30 AM

Hello I have a txt file of this formation
IP MAC
255.255.255.100 150.150.150.100
255.255.255.200 150.150.150.200
255.255.255.300 150.150.150.300
255.255.255.400 150.150.150.400
255.255.255.500 150.150.150.500

I want to read these data and check if the IP I insert manually
matches any of these IP's. I don't want to Process MAC column whatsoever.
What should I do?
Please be specific.
I know it is something with scanf but I dont now how I will store the Column that I want.
That is the key problem that I have.
Thanks in Advance.

#include<stdio.h>

	//Struct data
	typedef struct 
	    {
	    char *ip;
	    char *mac;
	    }data;

	int main()
	{	

		//Orismos metabliton.
    		FILE *ptr_file;
    		char buf[1000];
		char ip[1000];

		//Open txt file.
    		ptr_file =fopen("arp.txt","r");
		if (!ptr_file)
        	return 1;
		
		//Input IP from user
		scanf("%s",ip);
		//Test of input
		printf("%s\n",ip);
		
		//Reading txt.
    		while (fgets(buf,1000, ptr_file)!=NULL)
			//Reading check.        		
			printf("%s",buf);
			fclose(ptr_file);
    		
		return 0;
	}




Is This A Good Question/Topic? 0
  • +

Replies To: Compare data from a txt file and an input.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6031
  • View blog
  • Posts: 23,413
  • Joined: 23-August 08

Re: Compare data from a txt file and an input.

Posted 20 April 2013 - 04:24 AM

Perhaps you can use this

Quote

Each conversion specification in format begins with either the character '%' or the character sequence "%n$" (see below for the distinction) followed by:
An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned by scanf().


from the man page of scanf to come up with a possible solution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1