Basically i want this function to update the records in the file, but it should first prompt for the name of the employee and then retrieve the employee's details if the name matched any name in the file. Here is my attempt

void update(EMPLOYEE *details) /*EMPLOYEE refers to strusture variable i created*/
{
	FILE *file;
	char search;
	file = fopen("employees.txt","r");
	if(file == NULL)
	{
		printf("File error!!!");
		exit(0);
	}
	else
	{
		search = getc(file);
		printf("Enter name: ");
		scanf("%s",details->name);

		if((strcmp(search,details->name) == 0))
		{
			printf("%s\n",details->name);
	     	printf("%d",details->employeeNumber);
		}
	}
	

fclose(file);
}

Where exactly are you reading a string? getc is used to get a single character. You can try using fscanf() instead, and obtain a string. i hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.