C/Visual C - AYUDA!!! Codigo c++

 
Vista:

AYUDA!!! Codigo c++

Publicado por CcXD (1 intervención) el 15/11/2006 03:57:03
Hey ke tal!

parece ke tengo un problemita con una funcion en mi codigo de c++. Quiero eliminar informacion de un archivo, pero por alguna razon al leer la info del archivo para borrar, no se lee la 1era linea... aki les mando el codigo y el formato del archivo para que tengan una mejor idea.

void Delete_Book()
{

ifstream InFile;
ofstream OutFile;

char stuff [100] = {' '};
char ISBN [14];
char search[14];
int number;
bool found;

cin.ignore();

InFile.open("Info.txt");

InFile.getline(ISBN, 14, '*');
InFile.clear();
while (InFile.eof() != true)
{

cout << endl;

cout << "ISBN: " << ISBN << endl;

InFile.getline(stuff, 14, '*'); // getting author from file
cout << "Author: " << stuff << endl;

InFile.getline(stuff, 31, '\n'); //Getting Publisher from the file.
cout << "Publisher: " << stuff << endl;

InFile.getline(stuff, 51, '*'); // Getting Tittle from the file
cout << "Tittle: " << stuff << endl;



InFile >> number; //Getting Cost from file
cout << "Cost: $" << number << endl;

InFile.ignore(); // ignore '*' character

InFile >> number; //Getting price from the file
cout << "Price: $" << number << endl;

InFile.ignore();// ignore '*' character

InFile >> number; // getting books at hand from file
cout << "Books at hand: " << number << endl;

InFile.ignore(); //Ignore '\n' character

cout << endl;
InFile.getline(ISBN, 14, '*');

}


InFile.close();

InFile.open("info.txt");
OutFile.open("temp.txt");

InFile.clear();


while(InFile.eof() != true)
{
InFile.getline(stuff, 100);
OutFile << stuff << '\n';
cout << "stuff: " << stuff << endl;
}

cout << "After transfer" << endl;

InFile.close();
OutFile.close();

cout << "Choose which book to delete by its ISBN number: " ;
cin.getline(search, 14, '\n');
cout << "search: " << search << endl;

found = false;
system ("pause");

InFile.open("temp.txt");
OutFile.open("info.txt");

InFile.clear();
while(InFile.eof() != true)
{
if (strcmp(ISBN,search))
{
InFile.getline(stuff, 100);
OutFile << ISBN << '*' << stuff << '\n';
cout << ISBN << '*' << stuff << endl;
InFile.getline(stuff, 100);
OutFile << stuff << '\n';
cout << stuff << endl;

InFile.getline(ISBN, 14, '*');
}

else
{
InFile.ignore(100, '\n');
InFile.ignore(100, '\n');

InFile.getline(ISBN, 14, '*');

found = true;
}


}

if (found == false)
{
cout << "No match found for this ISBN" << endl;
}

else
{
InFile.close();
OutFile.close();
cout << "File deleted..." << endl;
system("pause");
}

}

**********************************
(formato del archivo "info.txt":

ISBN*Autor*Editorial
titulo*costo*precio*unidades

************************************

si alguien me puede ayudar con esto ke me tiene harto, porke funciona casi casi perfecto, le estrare super agradecido!!

Grax
Christian
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder