|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* fopen example */
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("myfile.txt","w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
}
return 0;
}
|
This post has been edited 1 times, last edit by "WebSTAR" (Apr 2nd 2008, 7:01pm)
Quoted
#include <"variablex.txt");
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <stdio.h>
int main (){
FILE *varfile;
// Versuche Datei zum lesen zu oeffnen
varfile = fopen( "variable.txt", "r" );
int myVar;
char yesNo;
myVar = 0;
// Gibt es die Datei schon oder nicht
if ( varfile != NULL ) {
// Abgespeicherte Zahl als Integer lesen
fscanf( varfile, "%d", &myVar );
printf( "Die gespeicherte Zahl war: %d \n", myVar );
} else {
printf( "Datei existiert nicht. Verwende Standardwert 0 \n" );
}
printf( "Neue Zahl eingeben? J oder N \n" );
yesNo = getchar();
if( yesNo == 'J' ){
scanf( "%d", &myVar );
// Datei zum Schreiben oeffnen
varfile = fopen( "variable.txt", "w" );
fprintf( varfile, "%d", myVar );
printf( "Die Variable hat jetzt den Wert : %d \n", myVar );
}
printf( "Auf Wiedersehen \n" );
}
|
Forum Software: Burning Board® 3.1.2, developed by WoltLab® GmbH