FILE HANDLING - Edit problem

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1728 Views - Last Post: 28 November 2010 - 09:34 AM Rate Topic: -----

#1 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

FILE HANDLING - Edit problem

Posted 28 November 2010 - 04:35 AM

Thank you janotte for helping me fixing the search... Now my problem was edit... my code works fine but the problem was like this:

Enter name to edit: john
ID: 001
Name: John
Gender: M
Amount: 123

Enter the new info:
ID: 001
Name: Jaja
Gender: M
Amount: 123

When i choose display it works fine but pretending to have a display section like this:

1 john m 123
2 maria m 123
3 bomz m 123

When i edit john, maria and bomz will be BOOM!! gone in the display section how could i fix it???
here is my code
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <iostream.h>
#define input "f:\\tcpp\\bin\\files\\input.txt"
#define tempo "f:\\tcpp\\bin\\files\\tempo.txt"
FILE *infile;
FILE *temp;
char Name[50], Target[50];
int ID = 0, found = 0;
float Amount;
char Gender;

void menu(void)
{
	cout << "Menu\n\n";
	cout << "A - Add\n";
	cout << "D - Delete\n";
	cout << "I - Display\n";
	cout << "E - Edit\n";
	cout << "S - Search\n";
	cout << "X - Exit\n\n\n";
	cout << "Enter your choice: ";
}

void add(void)
{
	if((infile = fopen(input, "a+")) == NULL)
		ID = 1;
	else
	{
		do{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
		}while(!feof(infile));
		ID += 1;
	}
	cout << "ID  :    " << ID << endl;
	cout << "Name:    ";
	cin >> Name;
	cout << "Gender:  ";
	cin >> Gender;
	cout << "Amount:  ";
	cin >> Amount;

	fprintf(infile, "%i %s %c %f\n", ID, Name, Gender, Amount);
	fclose(infile);
}

void deletes(void)
{
	temp = fopen(tempo, "w");

	if((infile = fopen(input, "r")) == NULL)
		printf("File Empty!");
	else
	{
		printf("Enter Name to delete: ");
		fflush(stdin);
		gets(Target);
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			if(strcmp(Target, Name) != 0)
				fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			else
			{
				found = 1;
				printf("ID:\t%04i\n", ID);
				printf("Name: %s\n", Name);
				if(toupper(Gender) == 'F')
					printf("Gender:\tFemale\n");
				else
					printf("Gender:\tMale\n");
				printf("Amount: %.2f\n", Amount);
			}
		}

		if (!found)
			printf("Record not found!\n");
	}
		printf("\nRecord deleted.");
		fclose(infile);
		fclose(temp);
		remove(input);
		rename(tempo, input);
}

void display(void)
{
	if((infile = fopen(input, "a+")) == NULL)
		cout << "File Empty!";
	else
	{
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			printf("%i %s %c %.2f\n", ID, Name, Gender, Amount);
		}
	}
	printf("\nEnd of file, press any key to exit.");
	fclose(infile);
}

void search(void)
{
	int found = 0;

	if ((infile = fopen(input, "r+")) == NULL)
		printf("File Empty!");
	else
	{
		cout << "Enter Name to search: ";
		cin >> Target;
		while(found == 0 && !feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(strcmp(Target, Name) == 0)
			found = 1;
		}
		if(found)
		{
			printf("ID:\t%04i\n", ID);
			printf("Name: %s\n", Name);
			if(toupper(Gender) == 'F')
				printf("Gender: Female\n");
			else
				printf("Gender: Male\n");
			printf("Amount: %.2f\n", Amount);
		}
	}
	fclose(infile);
}
void edit(void)
{
	int found = 0;
	temp = fopen(tempo, "w");
	if ((infile = fopen(input, "r+")) == NULL)
		printf("File Empty!");
	else
	{
		cout << "Enter Name to edit: ";
		cin >> Target;
		while(found == 0 && !feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(strcmp(Target, Name) != 0)
				fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			else
			{
				found = 1;
				printf("ID:\t%04i\n", ID);
				printf("Name: %s\n", Name);
				if(toupper(Gender) == 'F')
					printf("Gender:\tFemale\n");
				else
					printf("Gender:\tMale\n");
				printf("Amount: %.2f\n", Amount);
			}
		}

	}


		fclose(infile);
		fclose(temp);
		remove(input);
		rename(tempo, input);
		printf("Enter new information: \n");
	infile = fopen(input, "a+");
	cout << "ID  :    " << ID << endl;
	cout << "Name:    ";
	cin >> Name;
	cout << "Gender:  ";
	cin >> Gender;
	cout << "Amount:  ";
	cin >> Amount;

	fprintf(infile, "%i %s %c %f\n", ID, Name, Gender, Amount);
	fclose(infile);
	printf("Record edited!");
}
void main(void)
{
	char choice;
do{
	clrscr();
	menu();
	scanf("%c", &choice);
	switch(toupper(choice))
	{
	case 'A':
		clrscr();
		add();
		getch();
		break;
	case 'D':
		clrscr();
		deletes();
		getch();
		break;
	case 'I':
		clrscr();
		display();
		getch();
		break;
	case 'E':
		clrscr();
		edit();
		getch();
		break;
	case 'S':
		clrscr();
		search();
		getch();
		break;
	}
}while(toupper(choice) != 'X');
}



Is This A Good Question/Topic? 0
  • +

Replies To: FILE HANDLING - Edit problem

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 04:47 AM

What do lines 151 and 152 do?
Was This Post Helpful? 1
  • +
  • -

#3 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 05:03 AM

i made a condition like this:
{
while(strcmp(Target, Name) != 0 && !feof(infile))
				fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			if(strcmp(Target, Name) == 0)
			{
				found = 1;
				printf("ID:\t%04i\n", ID);
				printf("Name: %s\n", Name);
				if(toupper(Gender) == 'F')
					printf("Gender:\tFemale\n");
				else
					printf("Gender:\tMale\n");
				printf("Amount: %.2f\n", Amount);
			}
}

and replace what you have said,,,
i understand what youre asking me and i figured it out that when it found the target, it will be automatically found = 1 and then do what it was asked for.... now i made a condtion that will print on the file until it gets feof and == 0 but still have the same result :(

MOD EDIT: Added code tags. After 68 posts, I should NOT have to do that.

This post has been edited by JackOfAllTrades: 28 November 2010 - 06:15 AM

Was This Post Helpful? 0
  • +
  • -

#4 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 05:24 AM

i tried to put the fscanf inside the while loop
while(found == 0)
		{

			if(feof)
				break;
			//if(strcmp(Target, Name) != 0 && !feof(infile))
			  //	fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			while(strcmp(Target, Name) != 0 && !feof(infile))
			{
				fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
				fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			}
			if(strcmp(Target, Name) == 0)
			{
				found = 1;
				printf("ID:\t%04i\n", ID);
				printf("Name: %s\n", Name);
				if(toupper(Gender) == 'F')
					printf("Gender:\tFemale\n");
				else
					printf("Gender:\tMale\n");
				printf("Amount: %.2f\n", Amount);
			}
		}



i am thinking how i will be able to write the names that are not on target on the temp file and then if the target was found, i will make the same process

hey im reading your article of what have you tried... its really interesting :)...

This post has been edited by issyl: 28 November 2010 - 05:22 AM

Was This Post Helpful? 0
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 988
  • View blog
  • Posts: 5,135
  • Joined: 28-September 06

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 05:26 AM

I have no idea what you just said.

My question is, why are you writing to the file on line 152? (and in that stuff you just posted - remember code tags, like this :code:)
Why are you doing that?

Are you looking at the content of your data files before and after running your program?
If you aren't then you need to start doing that.
Open them in Notepad or similar and look at what you are doing to them. Does it look good and healthy?

BTW
I very much doubt there is any teacher in the USA who would steal their teaching wage by teaching you to code the rubbish you are being taught to code. You should really correct the country flag in your profile if you aren't in the US.
Was This Post Helpful? 1
  • +
  • -

#6 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 05:29 AM

Here’s a secret: willingness and desire to learn are the true qualifications

im still learning that principle :)

well then, :( i guess i really have to work on my own again thanks
Was This Post Helpful? 0
  • +
  • -

#7 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 06:22 AM

I already made the edit program but now my problem was the output....
here is my code then ill explain the output...
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <iostream.h>
#define input "f:\\tcpp\\bin\\files\\input.txt"
#define tempo "f:\\tcpp\\bin\\files\\tempo.txt"
FILE *infile;
FILE *temp;
char Name[50], Target[50];
int ID = 0, found = 0;
float Amount;
char Gender;

void menu(void)
{
	cout << "Menu\n\n";
	cout << "A - Add\n";
	cout << "D - Delete\n";
	cout << "I - Display\n";
	cout << "E - Edit\n";
	cout << "S - Search\n";
	cout << "X - Exit\n\n\n";
	cout << "Enter your choice: ";
}

void add(void)
{
	if((infile = fopen(input, "a+")) == NULL)
		ID = 1;
	else
	{
		do{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
		}while(!feof(infile));
		ID += 1;
	}
	cout << "ID  :    " << ID << endl;
	cout << "Name:    ";
	cin >> Name;
	cout << "Gender:  ";
	cin >> Gender;
	cout << "Amount:  ";
	cin >> Amount;

	fprintf(infile, "%i %s %c %f\n", ID, Name, Gender, Amount);
	fclose(infile);
}

void deletes(void)
{
	temp = fopen(tempo, "w");

	if((infile = fopen(input, "r")) == NULL)
		printf("File Empty!");
	else
	{
		printf("Enter Name to delete: ");
		fflush(stdin);
		gets(Target);
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			if(strcmp(Target, Name) != 0)
				fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
			else
			{
				found = 1;
				printf("ID:\t%04i\n", ID);
				printf("Name: %s\n", Name);
				if(toupper(Gender) == 'F')
					printf("Gender:\tFemale\n");
				else
					printf("Gender:\tMale\n");
				printf("Amount: %.2f\n", Amount);
			}
		}

		if (!found)
			printf("Record not found!\n");
	}
		printf("\nRecord deleted.");
		fclose(infile);
		fclose(temp);
		remove(input);
		rename(tempo, input);
}

void display(void)
{
	if((infile = fopen(input, "a+")) == NULL)
		cout << "File Empty!";
	else
	{
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			printf("%i %s %c %.2f\n", ID, Name, Gender, Amount);
		}
	}
	printf("\nEnd of file, press any key to exit.");
	fclose(infile);
}

void search(void)
{
	int found = 0;

	if ((infile = fopen(input, "r+")) == NULL)
		printf("File Empty!");
	else
	{
		cout << "Enter Name to search: ";
		cin >> Target;
		while(found == 0 && !feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(strcmp(Target, Name) == 0)
			found = 1;
		}
		if(found)
		{
			printf("ID:\t%04i\n", ID);
			printf("Name: %s\n", Name);
			if(toupper(Gender) == 'F')
				printf("Gender: Female\n");
			else
				printf("Gender: Male\n");
			printf("Amount: %.2f\n", Amount);
		}
	}
	fclose(infile);
}

void edit(void)
{
	int found = 0, back;
	temp = fopen(tempo, "a+");
	if ((infile = fopen(input, "r+")) == NULL)
		printf("File Empty!");
	else
	{
		cout << "Enter Name to edit: ";
		cin >> Target;
		while(found == 0)
		{
			while(!feof(infile))
			{
				fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
				if(strcmp(Target, Name) != 0)
					fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);
				else
				{
					back = ID;
					found = 1;
					printf("ID:\t%i\n", ID);
					printf("Name: %s\n", Name);
					if(toupper(Gender) == 'F')
						printf("Gender: Female\n");
					else
						printf("Gender: Male\n");
					printf("Amount: %.2f\n", Amount);
				}
			}
		}
		if(found)
		{

			ID = back;
			cout << "Enter new information\n\n";
			cout << "ID  :    " << ID << endl;
			cout << "Name:    ";
			cin >> Name;
			cout << "Gender:  ";
			cin >> Gender;
			cout << "Amount:  ";
			cin >> Amount;
			cout << "Record edited";

			fprintf(temp, "%i %s %c %f\n", ID, Name, Gender, Amount);


		}
	}
	fclose(infile);
	fclose(temp);
	remove(input);
	rename(tempo, input);
}
void main(void)
{
	char choice;
do{
	clrscr();
	menu();
	scanf("%c", &choice);
	switch(toupper(choice))
	{
	case 'A':
		clrscr();
		add();
		getch();
		break;
	case 'D':
		clrscr();
		deletes();
		getch();
		break;
	case 'I':
		clrscr();
		display();
		getch();
		break;
	case 'E':
		clrscr();
		edit();
		getch();
		break;
	case 'S':
		clrscr();
		search();
		getch();
		break;
	}
}while(toupper(choice) != 'X');
}



it works fine, it replaces the target and write it to the input but my problem was how come the names that are not on target gets doubled?

example:

Enter Name to edit: john
ID: 2
Name: john
Gender: Male
Amount: 123

Enter New information:

ID: 2
Name: jaja
Gender: Male
Amount: 123

When i saw my notepad .txt it became...

2 jaja m 123.0000
1 jojo m 123.0000
1 jojo m 123.0000

what should i fix??
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 06:37 AM

Merged duplicates. Do NOT create duplicate topics.
Was This Post Helpful? 0
  • +
  • -

#9 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 06:42 AM

sorry sir

jimblumberg pls helppp me :(
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 06:54 AM

Why all the globals?

Check if maybe you are reusing a global inside one of your functions.
(hint you are).

Never use these:

fflush(stdin);
gets(Target);


Using fflush(stdin) leads to undefined behavior.

Using gets leads to buffer overruns us fgets instead.

Never use void main() it should be int main() and return an int.

Is this code C++ or C? You should not mix C++ io and C io.

In you edit function why are you sure you are using 3 different files (input, temp, tempo)?

Jim

This post has been edited by jimblumberg: 28 November 2010 - 06:54 AM

Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 07:02 AM

Jim, he's been told REPEATEDLY about those problems, but refuses to update the code. Don't waste your typing fingers :)
Was This Post Helpful? 0
  • +
  • -

#12 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 08:10 AM

i give up ! what is the item that i've repeated? i tried to make a new one with the same method pls help me nowwwww i really wanted to sleep now... our quiz would be on tuesday plss or give me more clues :( sorry for using cout and cin.. by the time my program gets perfect, i'll be learning how to use fstream for c++ file i/o
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <iostream.h>
#define input "f:\\tcpp\\bin\\files\\input.txt"
#define tempo "f:\\tcpp\\bin\\files\\tempo.txt"

void menu(void)
{
	cout << "Menu\n\n";
	cout << "A - Add\n";
	cout << "D - Delete\n";
	cout << "I - Display\n";
	cout << "E - Edit\n";
	cout << "S - Search\n";
	cout << "X - Exit\n\n\n";
	cout << "Enter your choice: ";
}

void add(void)
{
	FILE *infile;
	
	char Name[50], Target[50];
	int ID = 0;
	float Amount;
	char Gender;

	if((infile = fopen(input, "a+")) == NULL)
		ID = 1;
	else
	{
		do{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
		}while(!feof(infile));
		ID += 1;
	}
	cout << "ID  :    " << ID << endl;
	cout << "Name:    ";
	cin >> Name;
	cout << "Gender:  ";
	cin >> Gender;
	cout << "Amount:  ";
	cin >> Amount;

	fprintf(infile, "%i %s %c %f\n", ID, Name, Gender, Amount);
	fclose(infile);
}

void deletes(void)
{
	FILE *infile;
	FILE *tfile;
	char Name[50], Target[50];
	int ID = 0, found = 0;
	float Amount;
	char Gender;
	tfile = fopen(tempo, "w");

	if((infile = fopen(input, "r")) == NULL)
		cout << "File Empty!" << endl;
	else
	{
		cout <<"Enter Name to delete: ";
		cin >> Target;
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			if(strcmp(Target, Name) != 0)
				fprintf(tfile, "%i %s %c %f\n", ID, Name, Gender, Amount);
			else
			{
				found = 1;
				cout << "ID:   " << ID << endl;
				cout << "Name: " << Name << endl;
				if(toupper(Gender) == 'F')
					cout << "Gender:\tFemale\n";
				else
					cout << "Gender:\tMale\n";
				cout << "Amount: " << Amount << endl;
			}
		}

		if (!found)
			cout << "Record not found!\n";
	}
		cout << "\nRecord deleted.";
		fclose(infile);
		fclose(tfile);
		remove(input);
		rename(tempo, input);
}

void display(void)
{
	FILE *infile;
	char Name[50], Target[50];
	int ID = 0;
	float Amount;
	char Gender;
	if((infile = fopen(input, "a+")) == NULL)
		cout << "File Empty!";
	else
	{
		while(!feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(feof(infile))
				break;
			cout << ID << " " << Name << " " << Gender << " " << Amount << endl;
		}
	}
	cout << "\nEnd of file, press any key to exit." << endl;
	fclose(infile);
}

void search(void)
{
	FILE *infile;
	char Name[50], Target[50];
	int ID = 0, found = 0;
	float Amount;
	char Gender;

	if ((infile = fopen(input, "r+")) == NULL)
		cout << "File Empty!";
	else
	{
		cout << "Enter Name to search: ";
		cin >> Target;
		while(found == 0 && !feof(infile))
		{
			fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
			if(strcmp(Target, Name) == 0)
			found = 1;
		}
		if(found)
		{
			cout << "ID:   " << ID << endl;
			cout << "Name: " << Name << endl;
			if(toupper(Gender) == 'F')
				cout << "Gender: Female\n";
			else
				cout << "Gender: Male\n";
			cout << "Amount: " << Amount << endl;
		}
	}
	fclose(infile);
}

void edit(void)
{
	FILE *infile;
	FILE *tfile;
	char Name[50], Target[50];
	int ID = 0, found = 0, back;
	float Amount;
	char Gender;
	tfile = fopen(tempo, "a+");
	if ((infile = fopen(input, "r+")) == NULL)
		cout << "File Empty!";
	else
	{
		cout << "Enter Name to edit: ";
		cin >> Target;
		while(found == 0)
		{
			while(!feof(infile))
			{
				fscanf(infile, "%i %s %c %f", &ID, Name, &Gender, &Amount);
				if(strcmp(Target, Name) != 0)
					fprintf(tfile, "%i %s %c %f\n", ID, Name, Gender, Amount);
				else
				{
					back = ID;
					found = 1;
					cout << "ID:   " << ID << endl;
					cout << "Name: " << Name << endl;
					if(toupper(Gender) == 'F')
						cout << "Gender: Female\n";
					else
						cout << "Gender: Male\n";
					cout << "Amount: " << Amount << endl;
				}
			}
		}
		if(found)
		{

			ID = back;
			cout << "Enter new information\n\n";
			cout << "ID  :    " << ID << endl;
			cout << "Name:    ";
			cin >> Name;
			cout << "Gender:  ";
			cin >> Gender;
			cout << "Amount:  ";
			cin >> Amount;
			cout << "Record edited!" << endl;

			fprintf(tfile, "%i %s %c %f\n", ID, Name, Gender, Amount);
		}
	}
	fclose(infile);
	fclose(tfile);
	remove(input);
	rename(tempo, input);

}
int main(void)
{
	char choice;
do{
	clrscr();
	menu();
	scanf("%c", &choice);
	switch(toupper(choice))
	{
	case 'A':
		clrscr();
		add();
		getch();
		break;
	case 'D':
		clrscr();
		deletes();
		getch();
		break;
	case 'I':
		clrscr();
		display();
		getch();
		break;
	case 'E':
		clrscr();
		edit();
		getch();
		break;
	case 'S':
		clrscr();
		search();
		getch();
		break;
	}
}while(toupper(choice) != 'X');
	return 0;
}


This post has been edited by issyl: 28 November 2010 - 08:13 AM

Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 08:18 AM

With this new code, what problems are you having?

What are your inputs?

What are your outputs?

What did you expect?

What are the contents of any files used?

Jim
Was This Post Helpful? 0
  • +
  • -

#14 issyl  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 118
  • Joined: 25-October 10

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 08:23 AM

how come when i edit something like this:

example:

Enter name to edit:
Name: 3 john

Enter new name:
Name: 3 jaja
display function:
1 jojo
2 ran
3 jaja
it works fine... but why is it that when i edit 1 jojo... the 3 jaja gets doubled :( its 12 midnight here now and im getting a bit scary(:))pls help me out :(

i tried to make some of my codes as a comment to know which part where ive gone wrong... and i think its in the looping.... i tried to change the mode of temp to w+ but still doesn't make any improvements... im still experimenting on the looping but problems gets bigger and bigger....

i tried having 1 while only with feof and found into 1 while.. (while(found == 0 && !feof(infile))
but still doesn't make any sense:(

This post has been edited by issyl: 28 November 2010 - 08:25 AM

Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: FILE HANDLING - Edit problem

Posted 28 November 2010 - 08:27 AM

Quote

What are the contents of any files used?


Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2