I have a customer record which i wish to modify so i wrote the following to modify it but each time i typed the name i want to modify it will not modify and prints not found!

void modify(){
	char another='y',choice,name[25],flag='n';
    long id;

    do
	{
	 //clrscr();
	 //rewind(fc);
	 
	 printf("SEARCH BY NAME : PRESS 1 ");
	 
	 fflush(stdin);
	 choice=getchar();
	 
	 if(choice=='1')
	    {
	     printf("ENTER CUSTOMER NAME : ");
	     fflush(stdin);
	     gets(name);
	     while(fread(newcous,size,1,fc)==1)
		{
		   if(strcmp(newcous->CName,name)==0)
		     {
		       news();
		       flag='y';
		       break;
		     }
		}
	    }
	 if(flag=='n')
	 {
		printf("CUSTOMER NOT FOUND............ !\n");
	 }
	 
	 printf("DO YOU WANT TO MODIFY ANOTHER CUTOMER(Y/N)");
	 fflush(stdin);
	
	}while(another=='Y');
	 another=getchar();
    //fclose(fc);

    //Addcostumer();





}
void news()
	{
	   char another='y';
	   //clrscr();
	 
	   fseek(fc,-size,SEEK_CUR);
		printf("CUSTOMER'S NEW NAME:");
		printf("CUSTOMER'S NEW ADDRESS:");
		printf("CUSTOMER'S NEW Puhelin:");
		
		fflush(stdin);
		gets(newcous->CName);
		
		fflush(stdin);
		gets(newcous->Address);
		
		fflush(stdin);
		gets(newcous->Puhelin);
		
		
		
		printf("UPDATE THE CUSTOMER RECORD (Y/N)");
		fflush(stdin);
		another=getchar();
		if(another=='y'||another=='Y')
		fwrite(newcous,sizeof(struct CustomerData),1,fc);
		rewind(fc);
	 }

Recommended Answers

First off, see this.
Next, see this, too. It contains the information that describes your problem.

Jump to Post

All 3 Replies

First off, see this.
Next, see this, too. It contains the information that describes your problem.
And this info is the most important of all.

I saw those links and i try to us fgets() instead of gets that i use but still, is still printing not found whenever i type the name i wanted to modify.

Then display the name you type in EXACTLY as the variable sees it. Is it character by character an identical match? Are there characters you don't normally see as characters in one of the names (like a trailing SPACE, TAB, CR, LF)?

Be a part of the DaniWeb community

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