Shop OBEX P1 Docs P2 Docs Learn Events
in C, anything like PBASIC/BS2 TerminalN to accept from keyboard? — Parallax Forums

in C, anything like PBASIC/BS2 TerminalN to accept from keyboard?

John KauffmanJohn Kauffman Posts: 653
edited 2014-01-25 05:31 in Propeller 1
I've tried a dozen search terms to find an answer to subj but no luck on forum.
Is possible? What is the correct terminology for search of forums?
Thanks.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2014-01-22 11:51
    Maybe you're looking for scanf?

    I'm sure simplelibraries can as well, but someone else will have to provide that link.

    libpropeller has a C++ serial object that can handle reading characters (link).
  • John KauffmanJohn Kauffman Posts: 653
    edited 2014-01-22 11:58
    Thanks for lead on terminology. I'm off and running w/ it.
  • Heater.Heater. Posts: 21,230
    edited 2014-01-22 11:59
    // Try googling for these to read characters and lines.
    fgetc();
    getc();
    getchar();
    gets();
    fgets();
  • Ron SutcliffeRon Sutcliffe Posts: 420
    edited 2014-01-22 11:59
    Search is not good but this link might help

    http://learn.parallax.com/propeller-c-simple-protocols/half-duplex-serial

    Ron
  • John KauffmanJohn Kauffman Posts: 653
    edited 2014-01-22 12:24
    Here is minimal test of scanf()
    I expect if I enter 5 the terminal will show result of 5
    But If I enter 5 then terminal shows result of 0
    If I change print format to %d3 then enter 5 terminal shows result of 03
    Any guesses?


    #include "stdio.h"
    #include "simpletools.h"
    int myInt;

    float main() {
    print("Enter an int\n");
    scanf("%d",myInt); // I enter 5
    print("int is %d",myInt); // prints 0
    return 0;
    }
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-01-22 12:38
    scanf requires a pointer. The compiler should have issued a warning about this if you have warnings enabled. Use scanf("%d", &myInt).

    A printf with a format of "%d3" will print a decimal value followed by the character "3". Maybe you meant "%3d", which will use a minimum of 3 columns for the decimal value.
  • Heater.Heater. Posts: 21,230
    edited 2014-01-22 12:42
    scanf requires pointers for its destination arguments, you have to use &myInt in this case.

    This works with the standard printf on my PC.
    #include "stdio.h"
    
    
    int myInt;
    
    
    float main() {
        printf("Enter an int\n");
        scanf("%d", &myInt);
        printf("int is %d\n", myInt);
        return 0;
    }
    
    
    
  • jazzedjazzed Posts: 11,803
    edited 2014-01-22 12:43
    If you're going to use print(), you should use scan(). Function scan() is to scanf() as print() is to printf().

    int var;
    scan("%d", &var); // the & is really important.

    I suggest looking at this book several times: http://publications.gbdirect.co.uk/c_book/
  • Heater.Heater. Posts: 21,230
    edited 2014-01-22 12:48
    By the way. main () should not return a float.

    Generally it's best to have all compiler warnings turned on with the -Wall option.
  • John KauffmanJohn Kauffman Posts: 653
    edited 2014-01-22 12:59
    Dave:
    Dumb mistake on my part to forget format syntax. That ...3 will be clue next time. Thanks

    Zicog;
    your code worked.
    I added include of simpletools
    I switched first printf to just print (other wise nothing on terminal). I'm looking for difference of print() and printf(). Maybe printf() require syntax values, not just single string.
    Much thanks
  • Jack3Jack3 Posts: 55
    edited 2014-01-23 05:14
    From the little I have learned, the print() is in simpletools.h and is a pared down version of the <stdio> to save memory space in the prop.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-23 08:48
    Just a clue... stdio.h represents Standard Input and Output . hexadecimal file

    This is a Standard Library for input and output in all version of C since the dawn of time.

    Since the Propeller is used mostly to send and receive one character at a time, the functions for character i/o are most useful.
  • Heater.Heater. Posts: 21,230
    edited 2014-01-23 14:33
    Loopy.
    Just a clue... stdio.h represents Standard Input and Output . hexadecimal file
    What on earth has hexadecimal got to do with it?

    stdin and stdout are character devices. Basically streams of bytes in and streams of bytes out. Since the dawn of time, as you say.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-25 04:42
    @ Heater
    Isn't the stdio.h file in hexidecimal? Aren't all C library files stored as such?
  • SRLMSRLM Posts: 5,045
    edited 2014-01-25 05:08
    @ Heater
    Isn't the stdio.h file in hexidecimal? Aren't all C library files stored as such?

    Not the PropGCC stdio.h: https://code.google.com/p/propgcc/source/browse/lib/include/stdio.h
  • Heater.Heater. Posts: 21,230
    edited 2014-01-25 05:31
    Loopy,
    Isn't the stdio.h file in hexidecimal? Aren't all C library files stored
    as such?
    No. You are confusing different types of file here.

    A C header file, for example stdio.h, is a plain ordinary text file that happens to contain declarations of functions, macros, variables etc. In fact anything you can write in C can go in a header file. A header is a C source file. In C++ it is common to put entire class definitions in header files, including all the stuff that gets compiled to actual executable code.

    A C library file is one or more C source files compiled into a binary format, "object files", and combined into a single file. Such library files can be
    linked into your program when you compile it, so called "static" linking, or perhaps dynamically loaded and linked when it is run. Think Windows DLL.

    When you use functions in your program that are defined in header files actually the compiler does not care if they are functions in your code, or in a library some place. That is the linkers job to find them.

    Hexadecimal has nothing to do with any of this. Hexadecimal is just a number format used when displaying data. That data could be the contents of a binary file, a text file, an image, whatever.
Sign In or Register to comment.