π
<-

Running native C programs with ndless 4.5

:32tins: :32tinsktpb: :32tinsktpn: :32tinscas: :32tinstpkc: :32tinstpktpb: :32tinstp: :32tinscastp: :32tinscmc: :32tinscx: :32tinscxcas:

Running native C programs with ndless 4.5

Unread postby klausen » 17 Feb 2019, 15:42

So now that I've installed ndless 4.5 on to my handheld and installed the ndless-sdk on my computer (ubuntu 18.04 lts), how I do I actually run a program written in C on my ti nspire? For example, the following method seems to compile:

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <os.h>

int main()
{
  int a;
  printf("Enter a number: ");
  scanf("%d",&a);

  printf("you entered %d\n",a);

  return 0;
}

Code: Select all
nspire-gcc -Wall -W -marm -Os -c practice.c -o practice.o
mkdir -p .
nspire-ld practice.o -o practice.elf -Wl,--nspireio
genzehn --input practice.elf --output practice.tns.zehn --name "practice"
make-prg practice.tns.zehn practice.tns
rm practice.tns.zehn


But when load the .tns file to my nspire I can't get it to run normally. The screen is black with no prompt unless I enter a number. But when I enter a number the program executes and then instantly terminates. How do you run programs with normal user I/O?
User avatar
klausen
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Level up: 60%
 
Posts: 2
Joined: 17 Feb 2019, 13:37
Gender: Not specified
Calculator(s):
MyCalcs profile
Class: not sure

Re: Running native C programs with ndless 4.5

Unread postby Adriweb » 17 Feb 2019, 15:48

You may want to use nspire-io. which provides a console-like UI and IO features. See the examples here: https://github.com/Vogtinator/nspire-io ... lo/hello.c

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14839
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: Running native C programs with ndless 4.5

Unread postby klausen » 17 Feb 2019, 22:39

I'm not seeing a directory named "lib", should I just copy the "include" directory to my .ndless directory?

Image
User avatar
klausen
Niveau 1: MD (Membre Débutant)
Niveau 1: MD (Membre Débutant)
Level up: 60%
 
Posts: 2
Joined: 17 Feb 2019, 13:37
Gender: Not specified
Calculator(s):
MyCalcs profile
Class: not sure

Re: Running native C programs with ndless 4.5

Unread postby Adriweb » 18 Feb 2019, 06:59

I guess you need to build it first?

I'll point Vogtinator to this topic just in case

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.9%
 
Posts: 14839
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: Running native C programs with ndless 4.5

Unread postby Vogtinator » 18 Feb 2019, 08:54

No need to build anything - the ndless sdk contains a prebuilt version of nspire-io.

The "-Wl,--nspireio" option works fine, but your program has two issues:

- It doesn't wait for the user after printing the final message, so it just quits.
- Stdout is line-buffered by default, which means only messages terminated by a newline are shown.

By disabling the buffer and waiting for a second, the program works as you expect:

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <os.h>

int main()
{
  int a;
  setbuf(stdout, NULL);
  printf("Enter a number: ");
  scanf("%d",&a);

  printf("you entered %d\n",a);
  msleep(1000);

  return 0;
}
User avatar
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Level up: 1.6%
 
Posts: 217
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):
MyCalcs profile


Return to Problèmes divers / Aide débutants

Who is online

Users browsing this forum: ClaudeBot [spider] and 29 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
2219 utilisateurs:
>2196 invités
>16 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)