Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12609 Discussions

C program reads from .txt file - error!

Altera_Forum
Honored Contributor II
1,000 Views

This is a real beginner question! 

 

I have a simple C program that reads from a txt file. I wrote it in the NIOS II IDE. The txt file is in the same directory on my hard drive as the C file. It's a real simple program - basically it reads from the file one character at a time, and outputs the characters to the screen. 

 

When I build the project, the txt file is added to the project list. However, when I run it on the hardware (a Stratix), it doesn't work.  

 

So I suppose it's not actually transferring the txt file to the device. Do I manually have to transfer the .txt file to the FLASH memory? How do I do this in the IDE? How do I have to modify my C code to find the txt file in the Flash memory? 

 

Thanks a megabyte! 

 

Studi 

 

 

ps: here is my C program, to be thorough: 

 

------------------ 

# include <stdio.h> 

 

int main (void) 

FILE *input; 

char c; 

 

//open file for reading only 

input = fopen("input.txt", "r");  

 

//check input file for errors - probably file does not exist 

if (input == NULL) 

fprintf(stderr, "Error - can not open file\n"); 

return 1; 

 

else  

printf("File opened successfully. Contents:\n\n"); 

 

while(1)  

{ /* keep looping... */ 

c = fgetc(input); 

if(c!=EOF)  

printf("%c", c);  

/* print the file one character at a time */ 

}  

else 

break; /* ...break when EOF is reached */ 

 

printf("\n\nNow closing file...\n"); 

fclose(input); 

 

return 0; 

 

 

------------ 

The output is: 

 

Error - can not open file
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
273 Views

put your .txt file into .zip arhive (not compressed!), 

Run nios IDE, 

 

your project&#39;s properties-> 

Associated System Library ->  

System Library Properties...->System Library->Software Components ->  

Altera Zip RO File System -> Zip File (uncompressed): add your zip-file.
0 Kudos
Reply