Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Homework 4 - read_addresses.c
- * Author: Roen Riehl
- * Date: 7/15/2019
- *
- ***/
- #include <stdio.h>
- #include <string.h>
- int Read_Data_File();
- struct address_t
- {
- int ip1, ip2, c1, c2;
- char name[30];
- };
- struct address_t adr1[32];
- int locality_t[100][2];
- int main()
- {
- Read_Data_File();
- return 0;
- }
- int Read_Data_File()
- {
- char buff[128];
- char string[50];
- FILE *file_ptr;
- int i;
- int checkresult;
- const char *sentinel = "0.0.0.0 none";
- file_ptr=fopen("CS222data.txt","r");
- if(file_ptr==NULL)
- {
- perror("Error openingCS222data.txt");
- return(-1);
- }
- for(i=1;i<=100;++i)
- {
- if (fgets(buff, sizeof(buff), file_ptr)!= NULL)
- {
- sscanf(buff, "%d.%d.%d.%d %s",&adr1[i].ip1,&adr1[i].ip2, &adr1[i].c1, &adr1[i].c2, adr1[i].name);
- {
- sprintf(string, "%d.%d.%d.%d %s",adr1[i].ip1,adr1[i].ip2, adr1[i].c1, adr1[i].c2, adr1[i].name);
- printf("|%s|\n", string);
- if (strcmp(sentinel, string) == 0) {
- printf("SUCCESS\n");
- return(-1);
- }
- }
- }
- }
- printf("%d", i);
- fclose(file_ptr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement