Forum Discussion
Altera_Forum
Honored Contributor
19 years agofopen 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
Honored Contributor
Hi omikron123,
> t always returns NULL -> why it'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 'string' ;-) --Scott - Altera_Forum
Honored Contributor
Hi Scott,
thx for your help but i can't fix it, can you give me an example how to initialize string greetz omikron