Forum Discussion
file io with NIOS II
- 5 years ago
Hi, Dong Wook
You are right.
However, there is another way, ie using a character-mode device like UART.
Below example is to write characters to a UART called uart1. You can find the device name (/dev/uart1) in the system.h
#include <stdio.h>
#include <string.h>
int main (void)
{
char* msg = "hello world";
FILE* fp;
fp = fopen ("/dev/uart1", "w");
if (fp!=NULL) { fprintf(fp, "%s",msg); fclose (fp);}
return 0;
}
Thanks.
Eric
Hi, Dong Wook
Can you forward your error log or picture to me ?
Thanks.
Eric
- euem7895 years ago
New Contributor
Appreciate for your reply Eric!
When I compiled , it said there was only an error with making elf file and others were fine.
Anyway, I solved the problem with elf file by increasing the amount of On-chip-memory.
but this time I faced another problem.... (reading file)
compile is enable and also able to run with hardware,
but the result is not what I wanted. ( with file path in eclipse I guess)
here's the code and also the console picture with it
#include <stdio.h> int main() { int num; FILE *fptr; if ((fptr = fopen("C:\\test_num.txt","r")) == NULL){ printf("Error! opening file"); return 0; } fscanf(fptr,"%d", &num); printf("Value of n=%d", num); fclose(fptr); return 0; }I'm wondering what's wrong this time, and also am I doing right...
thanks for reading