I have the following code, and I can't seem to find why my IF clause is not working within the while cycle. otherwise, I am able to pull the records from the text file. It appears that when i compare the searched value against the fetched value from the text nothing happens. I am trying to print out only those records by condition contained within the file.
/*
* File: main.c
* Author:
*
* Created on 06 February 2019, 10:27
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
*
*/
struct employee
{
char Name[100];
char Emp_ID[10];
char Sex[10];
char Department[50];
};
int main(int argc, char** argv) {
FILE *fp;
clearScreen();
struct employee emp;
fp=fopen("C:\\Users\\vdimitrov\\Documents\\NetBeansProjects\\KevinEngineering\\build\\Debug\\Cygwin-Windows\\employee.txt","r");
if (!fp) {
printf("Unable to open file!");
return -1;
}
printf("Display Employee Data Report");
while (fread(&emp,sizeof(struct employee),1,fp) != NULL) {
if(emp.Name == "Something contained in Name"){
printf("\n");
printf("\nName: %s\n", emp.Name);
printf("Emp_ID: %s\n", emp.Emp_ID);
printf("Sex: %s\n", emp.Sex);
printf("Department: %s\n", emp.Department);
}
}
printf("\nEnd Of Report\n");
fclose(fp);
return 0;
}
void clearScreen()
{
system("@cls||clear");
}