ts-7000
[Top] [All Lists]

Re: [ts-7000] TS-7400 segmentation fault with fprintf

To:
Subject: Re: [ts-7000] TS-7400 segmentation fault with fprintf
From: Rod <>
Date: Tue, 08 Jul 2008 12:10:16 +0200
With stream file operations you must use the 'fopen' call, not 'open', 
that's your problem.
You probably also got a compile warning that you fixed with the (FILE *) 
cast to convert the normally returned int to a FILE* type.
Anyway, use 'fopen' to open/create your file, the rest is fine.

Cheers

--
Rod



dglen2000 wrote:

> Hi guys, I am developing code on the TS7400 running debian, and I have
> encountered a problem with writing to files. I am new to writing
> software for debian, so please bear with me.
>
> my program exits after printing a segmentation fault... here is my
> code, its basically just a hello world to a file.
>
> int main (){
>
> FILE * f1 = (FILE*)(open("test.txt", O_RDWR|O_CREAT, S_IRUSR |
> S_IWUSR | S_IRGRP | S_IRWXO));
>
> if (f1!=NULL){
> printf("\nfile test.txt created\n");
> fprintf(f1,"Hi... im the file contents");
> fclose (f1);
> } else {
> printf("\nfile failed to open\n");
> fclose (f1);
> }
>
> return 0;
>
> }
>
> when I exicute the program it prints that the file is created, so I
> know I am not trying to write to a NULL pointer. Just after that the
> segmentation fault occurs. test.txt exists but is empty.
>
> Please tell me why this is happening, and what I can do to resolve it
>
> Thanks,
> David
>
>  


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU