Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: Roondak on September 28, 2013, 11:32:38 am

Title: Nspireio Help
Post by: Roondak on September 28, 2013, 11:32:38 am
So recently I've tried to use the ndless sdk to make some stuff for my calculator. Nspireio is pretty cool and all, but I really can't make sense of the documentation. I figured out how to use nio_printf as that's basically printf, but there's no nio_scanf... what am I supposed to do to take input?
Title: Re: Nspireio Help
Post by: ElementCoder on September 28, 2013, 11:38:35 am
I follow the way of the terminal demo:
Code: [Select]
while(1)
{
char text[100];
nio_printf("> ");

// No text given, exit console.
if(!nio_gets(text))
{
break;
}

if(!strcmp(text, "help"))
{
nio_printf("term help:\n----------\n");
}
}
Title: Re: Nspireio Help
Post by: Lionel Debroux on September 28, 2013, 11:42:14 am
Oh, gets without a size argument ? Not very secure :)

Feature request for nspireio, if it doesn't exist: add nio_getsn(), and rewrite
#define nio_gets(arg) nio_getsn(arg, sizeof(arg))
Title: Re: Nspireio Help
Post by: Roondak on September 28, 2013, 11:53:15 am
So basically... the basic input command is nio_gets. How do I get it to store the input as a variable? Or is text the variable being used in the example?
Title: Re: Nspireio Help
Post by: Lionel Debroux on September 28, 2013, 11:57:22 am
text is indeed the output variable.
Title: Re: Nspireio Help
Post by: ElementCoder on September 28, 2013, 11:57:36 am
@Lionel isn't that already in the declaration of text being 100 elements long?
@Roondak yes the variable text contains the text the user entered.
Title: Re: Nspireio Help
Post by: compu on September 28, 2013, 12:11:45 pm
Oh, gets without a size argument ? Not very secure :)
There is nio_fgets, which has a size argument. nio_gets is just there because it is ANSI C.

So recently I've tried to use the ndless sdk to make some stuff for my calculator. Nspireio is pretty cool and all, but I really can't make sense of the documentation. I figured out how to use nio_printf as that's basically printf, but there's no nio_scanf... what am I supposed to do to take input?
If you just want to use nspireio as a simple fullscreen console, you should take a look at the replace-stdio demo (https://github.com/compujuckel/nspire-io/blob/master/demo/replace-stdio/replace-stdio.c). Nspireio provides some functions from stdio.h, so you could just look at its documentation here (http://www.cplusplus.com/reference/cstdio/).

Title: Re: Nspireio Help
Post by: Roondak on September 28, 2013, 12:17:32 pm
Thanks for the help everyone! I think I got it from here... I just found the demo code a little confusing at fist.
Title: Re: Nspireio Help
Post by: Legimet on September 28, 2013, 10:38:09 pm
@Roondak you can use nio_fgets and then use sscanf() (which is a syscall) to parse the string easily.

@ElementCoder the gets function doesn't receive the size of the buffer as a parameter; in standard C, it just writes until it sees a newline or EOF, which can lead to buffer overflows.
In NspireIO, nio_gets just calls nio_fgets with a size parameter of 100, so if you have a buffer of size at least 100, you're safe; otherwise, you must use nio_fgets.

EDIT: compu added nio_scanf and nio_sscanf :)