Shop OBEX P1 Docs P2 Docs Learn Events
Get Values From Terminal - Propeller C - Start Simple — Parallax Forums

Get Values From Terminal - Propeller C - Start Simple

Hi

Need some assistance with one of the parallax tutorials.
I'm trying to replace scan and print functions with get and put functions, respectively.
The code below does not build, can somebody explain why and how to replace the sections of code that require the scan function with get commands. (I have marked the troubling code sections with "***" below).

Thanks

Code is below this line


#include "simpletools.h" // Include simple tools
int startVal;
int endVal;

int main() // Main function
{
putStr("Type values for startVal and \n");
putStr("endVal, separated by a space. \n");
putStr("Then, press Enter. \n");

getDec("%d%d", startVal);***
getDec("%d%d", endVal);***

putStr("\nCounting from ");

putDec(startVal);
putStr(" to ");
putDec(endVal);
putStr(".\n");

for(int n = startVal; n <= endVal; n++)
{
print("i = %d\n", n);***
}
putStr("\nDone!");
}

Comments

  • From the docs:
    int getDec	(void )		
    Get a decimal number from the debug port.
    Returns
    number received.
    
    I think readDec would work but it basically encapsulates scan* anyway:
    /**
     * @file getDec.c
     * Function to get decimal number from the terminal.
     *
     * Copyright (c) 2013, Parallax Inc.
     * Written by Steve Denson
     */
    #include <limits.h>
    #include "simpletext.h"
    
    int getDec(void)
    {
      extern text_t *dport_ptr;
      return readDec(dport_ptr);
    }
    
    int readDec(text_t *text)
    {
      int rc = 0;
      char buf[40];
      char *str = _safe_gets(text, buf, 39);
      if(*str)
        _scanf_getl(str, &rc, 10, 11, 1); /* signed */
      return rc;
    }
    
    /*
    

    Mike
  • AngryPickleAngryPickle Posts: 2
    edited 2018-10-07 10:13
    Thanks
Sign In or Register to comment.