I'm having trouble getting strcmp to return 0 for equal strings.
This is how my code looks (the relevant part anyway):
struct person{
char name[30];
time_t date;
char destination[30];
char phone[30];
};
in the main i have:
struct person act_person;
int f = open("persons.txt", O_RDONLY | O_CREAT, S_IRUSR);
if(f == -1){
//open error
}
char city_name[30];
scanf(" %[^\n]s", city_name);
city_name[strcspn(city_name, "\n")] = 0;
//lseek(f, 0, SEEK_SET); //took it out as user alk suggested
while(read(f, &act_person, sizeof(act_person))){
act_person.destination[strcspn(act_person.destination, "\n")] = 0;
if(strcmp(act_person.destination,city_name)==0){
printf("%s\n",act_person.name);
}
}
close(f);
The file I'm reading from was written to in similar byte sized chunks of person structs so it should work... yet no matter what i do strcmp will not return equal.
edit: I'm going to try to show a hexdump of the file to help find the problem as the user suggested, as soon as I figure out how to do just that
here is the dump: