dayvid75014
Messages postés96Date d'inscriptionmercredi 5 mars 2008StatutMembreDernière intervention25 avril 2008
-
1 avril 2008 à 16:36
dayvid75014
Messages postés96Date d'inscriptionmercredi 5 mars 2008StatutMembreDernière intervention25 avril 2008
-
2 avril 2008 à 09:39
Bonjour,
Je ne comprends pas pourquoi lorsque j'utilise un pointeur de fichier en dehors du main, cela me renvoie une erreur, comme si j'accédais à des endroits interdits ..
Bien sûr, si je réouvre le fichier pointé dans la fonction (càd en dehors du main), ça marche bien, mais le problème est qu'à chaque fois que je réouvre le fichier, ceci efface ce qui avait été inscrit dedans avant...
(pointeur de fichier texte pour écrire des données dedans)
Quelqu'un en connait la raison?
PS : c'est le même constat pour un autre pointeur de fichier vidéo
cs_laurent1024
Messages postés987Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention30 août 201225 1 avril 2008 à 17:14
Bonjour.
Ce n'est pas evident de te repondre sans le code qui va avec pour ton problème de pointeur de fichier.
Pour ecrire dans un fichier sans tout effacer il faut utiliser le mode "append" "a".
cs_laurent1024
Messages postés987Date d'inscriptionmardi 31 mai 2005StatutMembreDernière intervention30 août 201225 1 avril 2008 à 17:31
Voici un petit exemple :
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("myfile.txt","a");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
}
return 0;
}
et la liste des différent modes :
"r",
Open a file for reading. The file must exist.,
----
"w",
Create an empty file for writing. If a file with
the same name already exists its content is erased and the file is
treated as a new empty file.,
----
"a",
Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.,
----
"r+",
Open a file for update both reading and writing. The file must exist.,
----
"w+",
Create an empty file for both reading and writing.
If a file with the same name already exists its content is erased and
the file is treated as a new empty file.,
----
"a+",
Open a file for reading and appending. All writing
operations are performed at the end of the file, protecting the
previous content to be overwritten. You can reposition (fseek, rewind)
the internal pointer to anywhere in the file for reading, but writing
operations will move it back to the end of file. The file is created if
it does not exist.