A keyboard data entry routine
in
Programming Questions
•
1 years ago
Hi guys;
I am trying to do a routine to use a keyboard as a data entry like : enter a file name or enter a string. So for, my code work until I don't know how to use the data inside my array to make a string. A string is a array of char, and I use the CR - Enter key - ASCII code 10 or 0x0A to control my program.
I want this : char mydataset[i] ----> String myword so I can use the string variable later to use as a file name by example or use print(myword) or text(myword,30,30) in my program.
Any help would be nice.
My code work except I use a for() loop to print(mydataset[i]) and I don't know to make my array of char into a string. And I use a state variable to control my program. I don't want something like : ttttttttttttttttttttttt
The code do is : show the key and ASCII code, the number of key typed, display in the console the key typed ( an echo ) and print the array. But no string yet.
Here my code :
- char data;
- char[] mydataset = new char[255];
- int ascii;
- int count;
- int total;
- int state;
- String myword;
- void setup()
- {
-
- size(100,100);
- data=0;
- count=0;
- ascii=0;
- total=0;
- state=0;
- }
- void draw()
- {
- background(255);
- fill(0);
- ascii=int(data);
- text(data+" : "+ascii,20,20);
- if (data==10 && state==1)
- {
- for (int i=0;i<total+1;i++)
- {
- print(mydataset[i]);
- }
- total=0;
- state=0;
- }
- text("count : "+count,30,90);
- }
- void keyTyped()
- {
- data=key;
- mydataset[count]=data;
- print(data);
- if (data==10)
- {
- total=count;
- count=0;
- state=1;
- }
- else
- {
- count++;
- }
- }
1