www.digitalmars.com         C & C++   DMDScript  

D.gnu - File example

reply manfred toppoint.de writes:
Hi, 
 
import stream; 
import c.stdio; 
 
int main (char[][] args) { 
    File
dst = new File(); 
    dst.create("new_file"); 
    dst.writeString("Hi");
return 0; 
} 
 
I get the following errors, 
 
hansen hansen-lx:~/d/dli-0.1.2$
/file_write  
32727 3.272748e+04 
Permission denied 
Dumping core
Gleitkomma-Ausnahme 
 
----------    1 hansen   hansen          0 10. Apr 09:35
new_file 
 
Have someone a better example. Is it possible by  dst.create() to
change 
the mode, for example 777 . 
And how can i open a file for "read, write
or append"? 
 
Best Regards  
Manfred Hansen  
 
Apr 10 2003
parent Manfred Hansen <manfred toppoint.de> writes:
Hello,

this program read and write a file to disk.

import stream;
import c.stdio;

int main() {
        FILE *fpr;

        File kwd = new File("TODO"), dst = new File();
        fpr=fopen("test.txt","a");

        while (!kwd.eof()) {
                fprintf(fpr,kwd.readLine()~"\n","test.txt");
        }

        kwd.close;
        if((fclose(fpr)) != 0) {
                perror("fclose"); /* Reaktion auf Fehler */
        }

        return 0;
}

Regards,
Manfred Hansen
Apr 11 2003