I got my program to work but it seems it cannot:

1.cant read a file if its only one archive (needs two to be able to read)
2.can only read the first line in a FILE
3.delete function deletes more than one than intended.

help are appreciated :)

I have attached the file. thank you

It would be helpful to tell us the functions that are giving you problems. I'm not going to read all that code to try and guess what you want.

Thank you for replying.

There are 5 main functions;

1.add
2.edit
3.display
4.search
5.delete

add function & display function works but when it comes to other functions for e.g search function the program only reads the first file in the file and it gives error if there are no more than one item in the file..

the delete funtion works a bit but somehow it deleted 2 files at one time.. don't know whats wrong with my code

I opened it and.... well - 38KB of code! You need to isolate your problem, and not just give a whole project to someone else, to track.
This is also the C++ forum.

Are you missing something here(the brackets)?:

if(answer =='Y' || answer =='y')
				{
				remove("subject.dat");
				rename("temp.dat","subject.dat");
				printf("\nThe Record is deleted\n\n");
                }
                
           {	
			remove("temp.dat");
			printf("\nThe Record is NOT deleted\n\n");
		}

Sry i am new here or to any programming forums.

i dont see any problem with the codes you highlighted.

void searchStudent(void)
{

	char studentID[60] = {'\0'}; 
    char studentName[60] = {'\0'};
	char studentGender[60] = {'\0'};
	char studentDOB[60] = {'\0'};
	char studentAddress[60] = {'\0'};
	char studentPhone[60] = {'\0'};
	char studentGroup[60] = {'\0'};
	char target [20] = {'\0'};
	char answer;
 	int found = 0;
 	
	FILE *bFile;
    bFile = fopen("student.dat","r");
	system("cls");
	printf("\n");
	

printf("**************************SEARCH STUDENT RECORD**************************** ");

	   if (bFile == NULL)
                 printf("File could not be opened ");

else
    printf("\n Enter the ID of the student you want to search :");
	fflush(stdin);
	gets(target);

	while (!feof(bFile) && found == 0)
	{
						
		fscanf(bFile,"%[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c",studentID,studentName,studentGender,studentDOB,studentAddress,studentPhone,studentGroup);

		if (strcmp(target,studentID) == 0)
		{
					found = 1;

					fprintf(bFile,"%s,%s,%s,%s,%s,%s,%s,\n",studentID,studentName,studentGender,studentDOB,studentAddress,studentPhone,studentGroup);
		}

	}

		if (found)
		{
			printf("\nStudent ID			: %s",studentID);
			printf("\nStudent Name			: %s",studentName);
			printf("\nStudent Gender			: %s",studentGender);
			printf("\nStudent Date of Birth		: %s",studentDOB);
			printf("\nStudent Address			: %s",studentAddress);
			printf("\nStudent Phone Number		: %s",studentPhone);
			printf("\nStudent Group			: %s\n",studentGroup);
      }
      else
      printf("Record does not exist!\n\n");
      fclose(bFile);
      system("pause");
      mainMenu();
      
}

This is also the C++ forum.

Look again :)

It's just if() {} {} , shouldn't there be an 'else' between it?

Look again :)

:D lol, I think the doctor lied about these glasses.

ah that one, I've already corrected it. :)

the problem is my search function doesnt detect the second item in my FILE.

{

	char studentID[60] = {'\0'}; 
    char studentName[60] = {'\0'};
	char studentGender[60] = {'\0'};
	char studentDOB[60] = {'\0'};
	char studentAddress[60] = {'\0'};
	char studentPhone[60] = {'\0'};
	char studentGroup[60] = {'\0'};
	char target [20] = {'\0'};
	char answer;
 	int found = 0;
 	
	FILE *bFile;
    bFile = fopen("student.dat","r");
	system("cls");
	printf("\n");
	

printf("**************************SEARCH STUDENT RECORD**************************** ");

	   if (bFile == NULL)
                 printf("File could not be opened ");

else
    printf("\n Enter the ID of the student you want to search :");
	fflush(stdin);
	gets(target);

	while (!feof(bFile) && found == 0)
	{
						
		fscanf(bFile,"%[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c %[^,]%*c",studentID,studentName,studentGender,studentDOB,studentAddress,studentPhone,studentGroup);

		if (strcmp(target,studentID) == 0)
		{
					found = 1;

					fprintf(bFile,"%s,%s,%s,%s,%s,%s,%s,\n",studentID,studentName,studentGender,studentDOB,studentAddress,studentPhone,studentGroup);
		}

	}

		if (found)
		{
			printf("\nStudent ID			: %s",studentID);
			printf("\nStudent Name			: %s",studentName);
			printf("\nStudent Gender			: %s",studentGender);
			printf("\nStudent Date of Birth		: %s",studentDOB);
			printf("\nStudent Address			: %s",studentAddress);
			printf("\nStudent Phone Number		: %s",studentPhone);
			printf("\nStudent Group			: %s\n",studentGroup);
      }
      else
      printf("Record does not exist!\n\n");
      fclose(bFile);
      system("pause");
      mainMenu();
      
}

anything wrong here?

I think you are missing { and } in the code beginning on line 26

Also, you use fflush(stdin) a lot -- not a good thing to do. See this thread. You might also want to follow the other links shown at the bottom of that page.

It still doesn't work, the search and delete functions uses search function to find through ID, it cant seem to detect 2nd or 3rd item in file

anything wrong here?

Yes. In addition to what the Dragon mentioned,
1) you need to fix your formatting so we can follow your code;
2) you are using feof() incorrectly. This will cause you problems when the function seems to be working;
3) never, ever use gets(). Gives you a major problem in the wrong hands;
Read the links...

Are you sure you are reading the values correctly? And why are you calling mainMenu() at the end of the function?

In order to go back to the main menu after the function does it work. the search works now.

The edit and delete now give problems. The delete function deletes more than one intended. I can't use advanced syntax as because my level of C is basic only, I'm following the notes given by the lecturer.

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.