Author Topic: Nspireio Help  (Read 6208 times)

0 Members and 1 Guest are viewing this topic.

Offline Roondak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 54
  • Rating: +4/-3
    • View Profile
Nspireio Help
« 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?

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: Nspireio Help
« Reply #1 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");
}
}
« Last Edit: September 28, 2013, 11:38:59 am by ElementCoder »

Some people need a high five in the face... with a chair.
~EC

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Nspireio Help
« Reply #2 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))
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline Roondak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 54
  • Rating: +4/-3
    • View Profile
Re: Nspireio Help
« Reply #3 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?

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Nspireio Help
« Reply #4 on: September 28, 2013, 11:57:22 am »
text is indeed the output variable.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: Nspireio Help
« Reply #5 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.

Some people need a high five in the face... with a chair.
~EC

Offline compu

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 275
  • Rating: +63/-3
    • View Profile
Re: Nspireio Help
« Reply #6 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. Nspireio provides some functions from stdio.h, so you could just look at its documentation here.


Offline Roondak

  • LV3 Member (Next: 100)
  • ***
  • Posts: 54
  • Rating: +4/-3
    • View Profile
Re: Nspireio Help
« Reply #7 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.

Offline Legimet

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +29/-0
    • View Profile
Re: Nspireio Help
« Reply #8 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 :)
« Last Edit: September 29, 2013, 12:26:57 pm by Legimet »