Hi,
Please first, make sure you enable the altera_hostfs package by opening the BSP editor>>Software Packages tab>> Check the box in front of the altera_hostfs package.
Next is a sample code to read and write to a file at the host:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUF_SIZE (50)
int main(void)
{
FILE= fp_ascii = NULL;
FILE = fp_bin = NULL;
char buffer[BUF_SIZE];
int read_size=1;
/* Reading ASCII File from the host*/
fp_ascii = fopen("file path", "r");
if (fp_ascii == NULL)
{
printf("Cannot open the file\n");
exit(1);
}
fgets(buffer, sizeof(buffer), fp_ascii);
printf("%s", buffer);
fclose(fp_ascii);
/* WriteASCII File from the host*/
fp_ascii = fopen("file path", "w");
if (fp_ascii == NULL)
{
printf("Cannot open the file\n");
exit(1);
}
strcpy(buffer, "Hellow from NIOS II");
fputs(buffer, fp_ascii);
fclose(fp_ascii);
return 0;
}
Regards,