Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,065 Views

FILE * pointer declaration hangs uClinux

Hi all,  

 

I'm running uClinux (noMMU) on DE0 Nano. I'm trying to create a file and write to it via a C program. Example code: 

 

int main(void) 

FILE * fp; 

fp = fopen("test.txt","w+"); 

 

As soon as I run this the OS hangs. If I add a printf after the FILE * fp; command, nothing is printed. The OS hangs at the file declaration. Any ideas?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor I
32 Views

That can't be. Most likely fopen is dead-locked and preventing the stdout from flushing out the printf. Try doing a fflush (stdout) after the printf and before the fopen. I am assuming that main is getting called and that if the fopen call is not there, you do see the printf output. 

If the fopen is hanging, something must be wrong with the device it is trying to access. I am not too familiar with the uClinux/DE0 setup combination.
Altera_Forum
Honored Contributor I
32 Views

So I was going to try your suggestions but first thought I would remove ALL other code in the program. It worked!! Beginner mistake. I'll have to start adding my code and see where the train comes off the tracks. If it is relevant to this post I'll report back. Thanks for your reply. 

 

BTW, for other readers, the following code creates a text file and opens it for editing... 

 

int main(void) 

FILE * fp; 

fp = fopen("/bin/test_data.txt","w+"); 

//your code here 

fclose(fp); 

}
Reply