Forum Discussion
LucasM
New Contributor
7 years agoHow to read from stdin in NIOSII with the small_c_library
whithout the small_c_library checked, i am unable to read from standard input. unless there's some sort of alt_fopen, how do i read from the standard character streams whithout gets,scanf and fopen?...
- 7 years ago
It seems that with the small c library enabled stdin,stdou and stderr are "preopened" files, so i can interact with them as files whithout opening them, can't find right now exactly where i saw this info.
LucasM
New Contributor
7 years agoYes, i am able to read incoming data (from the uart) with the full C library, using:
#include <stdio.h>
#include <stdlib.h>
FILE * fp;
char msg[255];
fp = fopen("/dev/uart_0","r");
if(fp)
{
fscanf(fp,"%s",msg);
}I've tried using the alt library, but it fails with:
home/user/project_name/software/nios_project_name_bsp/HAL/src/alt_getchar.c:67: undefined reference to `getc'//source snippet
int
alt_getchar(void)
{
#ifdef ALT_SEMIHOSTING
char c;
read(STDIN_FILENO,&c,1);
return c;
#else
#ifdef ALT_USE_DIRECT_DRIVERS
ALT_DRIVER_READ_EXTERNS(ALT_STDIN_DEV);
char c;
if (ALT_DRIVER_READ(ALT_STDIN_DEV, &c, 1, alt_fd_list[STDIN_FILENO].fd_flags) <= 0) {
return -1;
}
return c;
#else
return getchar();
#endif
#endif
}It seems that the direct device drivers aren't available, and neither is getc.
is it some header missing or something similar?