Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

fopen don't work !!

Hi to all,

I need to use the fopen function but it didn't work ? When i try a fopen it always returns NULL -> why it's ANSI C standart ??????

# include <stdio.h>

FILE *fp;

char string[4000];

int main()

{

if (fp = fopen( string , "w"))

{

// got a filepointer

fprintf (fp,"yipie\n");

}

return 0;

}

thx to all http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif

-> Background : I have to port a program which uses a lot of fprintfs and i can set the first parameter of this function per# define at the begining of the prgram. In the original program this parameter is "stdout". I want that the frintf function writes to "string" and not to stdout. Thats why i try to do a fopen to a string (look at the example above)

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi omikron123,

    > t always returns NULL -> why it&#39;s ANSI C standart ??????

    Just a crazy thought ...

    > char string[4000];

    > ...

    > if (fp = fopen( string , "w"))

    ... maybe you need to pass fopen a valid path? Try initializing &#39;string&#39; ;-)

    --Scott
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Scott,

    thx for your help but i can&#39;t fix it, can you give me an example how to initialize string

    greetz omikron