hi.. i'm writing a program where a file contains a set of phonenumbers. when a customer buys a number that particular number has to be deleted from the file. i'm able to delete that number but when the next customer comes that number is still available. even though the number is not available in the file i dont know why its still appering when the next customer asks for that number.. can any1 help me with it ...

Perhaps you TRIED to delete the phone number, and didn't really succeed, or the number is stored in memory. Or it's a Zombie phone number! ;)

A thought: if you write data to a file, and the disk holding the file is set up for disk caching (the default for most OS's), then if you don't fflush(filePointerName), the data may not be written out to the file, right away.

Try fflush() and see if that helps. If not, you need to tell us more about your system, and how the data is being stored.

after deleting if i go back and check in the file that number is not available.that particular line is blank. but when i run the program again and if another customer ask for that number then that number is available-even if the number is not there in the file ...
i dont know from where that number is coming...

Then I surmise that your program either includes numbers that are not assigned, (i.e. blank), as available numbers, or it rebuilds it's list of available numbers, each time it starts, with blank numbers being restored and put as available.

Sometimes, when you have a record, and you want to remove it, the program doesn't actually *remove* the record. Instead, it just "zero's it out", by assigning a value to it that tells the program "this number is not available".

That value (a sentinel value), may be 0, -1, -99 or any number of choice that wouldn't normally be used, you see?

Do you have some code you can post or doc's for this program?

fp2=fopen("/home03/users/pin108/test/team2/database/Number_DB","r");
                        while(fgets(fnumber,11,fp2)!=NULL)
                        {
                            like=no;
                            if((fnumber[0]=='9')&&(fnumber[1]=='1')&&(fnumber[2]=='0')&&(fnumber[3]='2'))
                            {
                                if((fnumber[4]=='1'))
                                {
                                    if(!((fnumber[5]==fnumber[6]&&fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[5]==fnumber[6]+1&&fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[5]==fnumber[6]-1&&fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1)))
                                    {
                                    if((fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1))
                                    {
                                        printf("Do u like this number %s?\n",fnumber);
                                        l7 : printf("Enter 1 if yes or 0 if no\n");
                                        scanf("%d",&flagn);
                                        if(flagn==1)
                                        like=yes;
                                        else if(flagn==0)
                                            like=no;
                                        else
                                        {
                                            printf("Invalid entry\n");
                                            goto l7;
                                        }

                                        if(like==yes)
                                        {
                                            printf("You have been charged Rs.500 for this number\n");
                                            fp3=fopen("/home03/users/pin108/test/team2/database/soldNumber_DB","a");
                                            fputs(fnumber,fp3);
                                            fputs("      ",fp3);
                                            fputs("   Karnataka",fp3);
                                            fputs("      ",fp3);
                                            fputs("Customer",fp3);
                                            fputs("      ",fp3);
                                            fputs(" Prepaid",fp3);
                                            fputs("      ",fp3);
                                            fputs("  GOLD",fp3);
                                            fputs("      ",fp3);
                                            fputs(" Rs.500",fp3);
                                            fputs("      ",fp3);
                                            lt=time(NULL);
                                            ptr=localtime(&lt);
                                            fputs(asctime(ptr),fp3);
                                            fclose(fp3);
                                            deleteline(fnumber);
                                        }
                                    }
                                }
                                }

                            }

                            if(like==yes)
                                    break;
                            else
                                continue;
                        }
                        fclose(fp2);
                            break;

when i run this code number like 9102000000 appears twice even though if its not available in number_DB file

Can you quickly edit the program, highlight the code, and click on the CODE icon in the editing window?

Almost impossible to study code, that is smashed over all to the left hand side like html text.

fp2=fopen("/home03/users/pin108/test/team2/database/Number_DB","r");
while(fgets(fnumber,11,fp2)!=NULL)
{
like=no;
if((fnumber[0]=='9')&&(fnumber[1]=='1')&&(fnumber[2]=='0')&&(fnumber[3]='2'))
{
if((fnumber[4]=='1'))
{
if(!((fnumber[5]==fnumber[6]&&fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[5]==fnumber[6]+1&&fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[5]==fnumber[6]-1&&fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1)))
{
if((fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1))
{
printf("Do u like this number %s?\n",fnumber);
l7 : printf("Enter 1 if yes or 0 if no\n");
scanf("%d",&flagn);
if(flagn==1)
like=yes;
else if(flagn==0)
like=no;
else
{
printf("Invalid entry\n");
goto l7;
}

if(like==yes)
{
printf("You have been charged Rs.500 for this number\n");
fp3=fopen("/home03/users/pin108/test/team2/database/soldNumber_DB","a");
fputs(fnumber,fp3);
fputs(" ",fp3);
fputs(" Karnataka",fp3);
fputs(" ",fp3);
fputs("Customer",fp3);
fputs(" ",fp3);
fputs(" Prepaid",fp3);
fputs(" ",fp3);
fputs(" GOLD",fp3);
fputs(" ",fp3);
fputs(" Rs.500",fp3);
fputs(" ",fp3);
lt=time(NULL);
ptr=localtime(&lt);
fputs(asctime(ptr),fp3);
fclose(fp3);
deleteline(fnumber);
}
}
}
}

}

if(like==yes)
break;
else
continue;
}
fclose(fp2);
break;

You only get code tags by clicking on the icon, in the editing window, and pasting your code, between the tags it provides.

I'm putting together a program from your code, and have found a few odd errors, but I need to have you post the delete() function code. The code here, calls that function, to actually delete the number. This code just gets the number, and adds it to the end of the file.

No deletions going on here.

I'm too tired to continue this morning, but post up the delete function, and I'll get to it tomorrow. Perhaps others will get to it even sooner.[CODE ] icon, in the editing window, and pasting your code, between the tags it provides.

I'm putting together a program from your code, and have found a few odd errors, but I need to have you post the delete() function code. The code here, calls that function, to actually delete the number. This code just gets the number, and adds it to the end of the file.

No deletions going on here.

I'm too tired to continue this morning, but post up the delete function, and I'll get to it tomorrow. Perhaps others will get to it even sooner.

int deleteline(char *pnum)
		{
			strcpy(lnum,pnum);
			fp1= fopen("/home03/users/pin108/test/team2/database/Number_DB","r");
			fpt=fopen("/home03/users/pin108/test/team2/database/temp","w");
			while(fgets(number,11,fp1)!=NULL)
				{
					if(strcmp(number,lnum))  
					fputs(number,fpt);
				
						
					
				}
			fputs("\0",fpt);	

			fclose(fpt);
			fclose(fp1);
			remove("/home03/users/pin108/test/team2/database/Number_DB");
			rename("/home03/users/pin108/test/team2/database/temp","/home03/users/pin108/test/team2/database/Number_DB");
			return(0);
		}
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
	FILE *fp1,*fp2,*fp3,*fpt;
	
	char number[11],fnumber[11],str[1024],tem[11],pnum[11],lnum[11];
	
	int i=0,z,r=0,r1,s;
	int like,yes=1,no=0;
	
	
	int flagn;

	
	struct tm *ptr;
	time_t lt;
	int deleteline(char *pnum)
		{
			strcpy(lnum,pnum);
			fp1= fopen("/home03/users/pin108/test/team2/database/Number","r");
			fpt=fopen("/home03/users/pin108/test/team2/database/temp","w");
			while(fgets(number,11,fp1)!=NULL)
				{
					if(strcmp(number,lnum))  
					fputs(number,fpt);
				
						
					
				}
			fputs("\0",fpt);	

			fclose(fpt);
			fclose(fp1);
			remove("/home03/users/pin108/test/team2/database/Number");
			rename("/home03/users/pin108/test/team2/database/temp","/home03/users/pin108/test/team2/database/Number");
			return(0);
		}

		fp2=fopen("/home03/users/pin108/test/team2/database/Number","r");
		while(fgets(fnumber,11,fp2)!=NULL)
							{
								like=no;
								if((fnumber[0]=='9')&&(fnumber[1]=='1')&&(fnumber[2]=='0')&&(fnumber[3]='2'))
								{
									if((fnumber[4]=='1'))
									{
										if((fnumber[5]==fnumber[6]&&fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[5]==fnumber[6]+1&&fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[5]==fnumber[6]-1&&fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1))
										{
											

											printf("Do u like this number %s?\n",fnumber);
											l6 : printf("Enter 1 if yes or 0 if no\n");
											scanf("%d",&flagn);
											if(flagn==1)
											like=yes;
											else if(flagn==0)
												like=no;
											else
											{
												printf("Invalid entry\n");
												goto l6;
											}

											if(like==yes)
											{
												printf("your number is %s\n",fnumber);
												printf("You have been charged Rs.1000 for this number\n");
												fp3=fopen("/home03/users/pin108/test/team2/database/soldNumber","a");
												fputs(fnumber,fp3);
												fputs("      ",fp3);
												fputs("   Karnataka",fp3);
												fputs("      ",fp3);
												fputs("Customer",fp3);
												fputs("      ",fp3);
												fputs(" Prepaid",fp3);
												fputs("      ",fp3);
												fputs("   VIP",fp3);
												fputs("      ",fp3);
												fputs("Rs.1000",fp3);
												fputs("      ",fp3);
												lt=time(NULL);
												ptr=localtime(&lt);
												fputs(asctime(ptr),fp3);
												fclose(fp3);
												fclose(fp2);
												deleteline(fnumber);
											}
										}
									}
								}
								
								
								if(like==yes)
										break;
								else
									continue;

								
							}
							fclose(fp2);
					printf("Thank u\n");
}
#include <stdio.h>
#include <time.h>
#include <string.h>
int main()
{
	FILE *fp1,*fp2,*fp3,*fpt;
	
	char number[11],fnumber[11],str[1024],tem[11],pnum[11],lnum[11];
	
	int i=0,z,r=0,r1,s;
	int like,yes=1,no=0;
	
	
	int flagn;

	
	struct tm *ptr;
	time_t lt;
	int deleteline(char *pnum)
		{
			strcpy(lnum,pnum);
			fp1= fopen("/home03/users/pin108/test/team2/database/Number","r");
			fpt=fopen("/home03/users/pin108/test/team2/database/temp","w");
			while(fgets(number,11,fp1)!=NULL)
				{
					if(strcmp(number,lnum))  
					fputs(number,fpt);
				
						
					
				}
			fputs("\0",fpt);	

			fclose(fpt);
			fclose(fp1);
			remove("/home03/users/pin108/test/team2/database/Number");
			rename("/home03/users/pin108/test/team2/database/temp","/home03/users/pin108/test/team2/database/Number");
			return(0);
		}

		fp2=fopen("/home03/users/pin108/test/team2/database/Number","r");
		while(fgets(fnumber,11,fp2)!=NULL)
							{
								like=no;
								if((fnumber[0]=='9')&&(fnumber[1]=='1')&&(fnumber[2]=='0')&&(fnumber[3]='2'))
								{
									if((fnumber[4]=='1'))
									{
										if((fnumber[5]==fnumber[6]&&fnumber[6]==fnumber[7]&&fnumber[7]==fnumber[8]&&fnumber[8]==fnumber[9])||(fnumber[5]==fnumber[6]+1&&fnumber[6]==fnumber[7]+1&&fnumber[7]==fnumber[8]+1&&fnumber[8]==fnumber[9]+1)||(fnumber[5]==fnumber[6]-1&&fnumber[6]==fnumber[7]-1&&fnumber[7]==fnumber[8]-1&&fnumber[8]==fnumber[9]-1))
										{
											

											printf("Do u like this number %s?\n",fnumber);
											l6 : printf("Enter 1 if yes or 0 if no\n");
											scanf("%d",&flagn);
											if(flagn==1)
											like=yes;
											else if(flagn==0)
												like=no;
											else
											{
												printf("Invalid entry\n");
												goto l6;
											}

											if(like==yes)
											{
												printf("your number is %s\n",fnumber);
												printf("You have been charged Rs.1000 for this number\n");
												fp3=fopen("/home03/users/pin108/test/team2/database/soldNumber","a");
												fputs(fnumber,fp3);
												fputs("      ",fp3);
												fputs("   Karnataka",fp3);
												fputs("      ",fp3);
												fputs("Customer",fp3);
												fputs("      ",fp3);
												fputs(" Prepaid",fp3);
												fputs("      ",fp3);
												fputs("   VIP",fp3);
												fputs("      ",fp3);
												fputs("Rs.1000",fp3);
												fputs("      ",fp3);
												lt=time(NULL);
												ptr=localtime(&lt);
												fputs(asctime(ptr),fp3);
												fclose(fp3);
												fclose(fp2);
												deleteline(fnumber);
											}
										}
									}
								}
								
								
								if(like==yes)
										break;
								else
									continue;

								
							}
							fclose(fp2);
					printf("Thank u\n");
}

hey this is the entire code ... when i run this program after i accept the 1st number if i run the program again n keep saying no no then the already accepted number comes again ... plz jus lemme kno wats the error ...
the file number contains numbers like
9102100000
9102100001
.
.
.
9102199999


plz help

Still can't read the code with 20 TABs for indentation.

Convert all your TABs to 4 spaces which is a standard spacing for code. You might want to see this

You have no deleteline function(), you just included some code for it, inside main().

You should add a function prototype above int main(), like:

void deleteline(char *pnum);

//then your actual function (located OUTSIDE main(), would begin with:
void deleteline(char *pnum) {
  //put your deleteline function, in here. 

  //gotta love that copy and paste! 
  }

please set your editor up, like WaltP has suggested. Your code is almost unreadable, in it's current form.

The above may not solve your delete problem, but you need to do this FIRST, and THEN you can tell me what's wrong with it, altogether. Hopefully, by then I can see the whole program, on one page width.

There is some nice code in deleteline. It's just in the wrong place, and may need a bit of a touch up.

Back in a few hours to see how you're doing.

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.