Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

scanf

Can anyone plz tell me how to input data from the keyboard ??? i'm using nios II v7.2

had tried this code earlier(input the matrix and display it)

# include"system.h"# include"altera_avalon_pio_regs.h"# include"alt_types.h"# include<stdio.h># define m 5

static int a[m][m];

int main(void)

{

int i,j;

int order;

printf("\nenter the elements of array a\n");

for(i=0;i<=order;i++){

for(j=0;j<=order;j++)

scanf("%i", &a[j]);

}

printf("\the elements of array a\n");

for(i=0;i<=order;i++){

for(j=0;j<=order;j++)

printf("%i", &a[j]);

}

}

and i'm getting an error as

Linking hello_world_2.elf...

obj/hello_world.o(.text+0x6c): in function `main':

../hello_world.c:14: undefined reference to `scanf'

collect2: ld returned 1 exit status

thanx

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Try smth like this:

    char in_st[ 512 ];

    gets ( in_st );

    sscanf(in_str,"%i %i %i", &a[1], &a[2], &a[i][3]);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    scanf/sscanf isn't supported when some of the code reduction options are checked.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i know its an old thread but i have the same problem.. did you find a solution for this?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hmm.. but when you disable small c my RAM overflows.. ill find a way :) thanks a lot

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    scanf/printf (because of floating point support, I believe) take up a _lot_ of memory. I wouldn't advocate using them in small footprint systems...at least not the ones that are shipped with most libc implementations that is :-)

    There are other options.

    Cheers,

    slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    How do you disable a small footprint option? I created a small hello_c and now I can't get strtoi function working...is there a way to modify the footprint options after a project is already created?