in C, anything like PBASIC/BS2 TerminalN to accept from keyboard?
John Kauffman
Posts: 653
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.
Is possible? What is the correct terminology for search of forums?
Thanks.
Comments
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).
fgetc();
getc();
getchar();
gets();
fgets();
http://learn.parallax.com/propeller-c-simple-protocols/half-duplex-serial
Ron
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;
}
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.
This works with the standard printf on my PC.
int var;
scan("%d", &var); // the & is really important.
I suggest looking at this book several times: http://publications.gbdirect.co.uk/c_book/
Generally it's best to have all compiler warnings turned on with the -Wall option.
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
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.
stdin and stdout are character devices. Basically streams of bytes in and streams of bytes out. Since the dawn of time, as you say.
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
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.