TextEdit

Discussion specific to projects ideas and support.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: TextEdit

Post by mattallen37 »

You are right, I did forget the ";". I haven't compiled it, I just copied and heavily modified preexisting code. What is a "STACKOVERFLOW"? I have used that method of mine, and it seems to work actually really well for me.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: TextEdit

Post by nxtboyiii »

mattallen37 wrote:
nxtboyiii wrote:I have enhanced FW 1.21...
I don't think there is such a thing as enhanced firmware 1.21.
Oops. :oops: I meant to say 1.31.
Thanks, and have a nice day,
nxtboy III

programnxt.com
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: TextEdit

Post by dudmaster »

Mattallen, can you modify your program to output to the variable "Sen" (not an array)
2Labz.com, My Website
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: TextEdit

Post by mattallen37 »

dudmaster wrote:Mattallen, can you modify your program to output to the variable "Sen" (not an array)

Code: Select all

if(OpenFileRead("File.txt", size, handle) == NO_ERR)
{
  until (Sdone == true)  // read the text file till the end
  {
    if(ReadLnString(handle,message) != NO_ERR) Sdone = true;
    //You need to grab the message and write it to another string(or whatever you need to do) all right here.
    //Base it on an increasing variable, like the following lines.
    Sen[i]=message;
    i++
  }
}
There, like that? I know you don't want it to be an array, but it must be, or you will only get the last line of the file. If you really do only want the last line, then just take out the i++ and the . I suggest though that you just stick to the original.

How about this?

Code: Select all

if(OpenFileRead("File.txt", size, handle) == NO_ERR)
{
  until (Sdone == true)  // read the text file till the end
  {
    if(ReadLnString(handle,message) != NO_ERR) Sdone = true;
    //You need to grab the message and write it to another string(or whatever you need to do) all right here.
    //Base it on an increasing variable, like the following lines.
    TotalMessage[i]=message;
    i++
  }
  Sen=TotalMessage[Line];//Line being a variable or constant in the range of 0-(number of lines-1)
}
Using that UNTESTED code, you can read a multiple line text file (or what-have-you), and it stores each line into the TotalMessage array. To extract a specific line, use this part.

Code: Select all

Sen=TotalMessage[Line];
where Line is the line you want to extract (starting with 0).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: TextEdit

Post by dudmaster »

The program is great. Thanks, maybe i can add all lines together, and i can use the variable i to find out how many lines, correct?
2Labz.com, My Website
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: TextEdit

Post by dudmaster »

Well, i can't get the code to compile.

I got muntoo's code to compile but when i use it i get a -5 error.

Here is the code:

It takes the array and adds all the lines into one variable.

Code: Select all

void ReadLines(string &out[], string filename)
{
byte handle;
int fsize = 300;
ArrayInit(out, "", 0);
if(OpenFileRead(filename, fsize, handle) == LDR_SUCCESS)
{
for(string szBuf; (ReadLnString(handle, szBuf) == LDR_SUCCESS); ArrayBuild(out, out, szBuf));
CloseFile(handle);
}
}
task main() {
bool Sdone;
int size = 300, i, n;
byte handle;
string message, Full;
string Sen[100000000];
ReadLines(Sen, "Test3.txt");
int ArrLen = ArrayLen(Sen);
while (n < ArrLen)
{
string Dude = Sen[n];
Full = Full + Dude;
}
int TextWrap = 0;
while (0 == ButtonCount(BTNCENTER, true))
{
if (ButtonCount(BTNLEFT, true) && TextWrap > 0)
{
  TextWrap = TextWrap - 100;
}
if (ButtonCount(BTNRIGHT, true) && TextWrap < StrLen(Full) - 99)
{
  TextWrap = TextWrap + 100;
}
TextOut(0, LCD_LINE1, SubStr(Full, TextWrap, 18), true);
TextOut(0, LCD_LINE2, SubStr(Full, TextWrap + 16, 18));
TextOut(0, LCD_LINE3, SubStr(Full, TextWrap + 32, 18));
TextOut(0, LCD_LINE4, SubStr(Full, TextWrap + 48, 18));
TextOut(0, LCD_LINE5, SubStr(Full, TextWrap + 64, 18));
TextOut(0, LCD_LINE6, SubStr(Full, TextWrap + 80, 18));
TextOut(0, LCD_LINE7, SubStr(Full, TextWrap + 96, 18));
TextOut(0, LCD_LINE8, SubStr(Full, TextWrap + 112, 18));
if (ButtonCount(BTNEXIT, true))
{
  Stop(true);
}
Wait(50);
}
}
}
2Labz.com, My Website
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: TextEdit

Post by muntoo »

Paint.NET "Caligraphy Toolbox" Plugin SDK
Chrome Extension Development/Themes.

@Matt
Technically, I believe it would be called a buffer overflow, but StackOverflow cooler. :D
Buffer overflows are one of the oldest hacking techniques used to execute arbitary code. I don't understand the details, but here's a simple explaination:

Code: Select all

byte badCode[] = {0x10, 0x20, 0x30, 0x42, 0x2A, 0x10, 0x10, 0x10}; // Instructions in machine language
byte temp[3];
temp[0] = 0x10;
temp[1] = 0x20;
temp[2] = 0x30;
temp = badCode;
//temp[3] == 0x42!!!
I'll add more to this later...

Dud, look here:
https://sourceforge.net/apps/phpbb/mind ... 2865#p2865
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: TextEdit

Post by mattallen37 »

muntoo wrote:@Matt
Technically, I believe it would be called a buffer overflow, but StackOverflow cooler. :D
Buffer overflows are one of the oldest hacking techniques used to execute arbitary code. I don't understand the details, but here's a simple explaination:

Code: Select all

byte badCode[] = {0x10, 0x20, 0x30, 0x42, 0x2A, 0x10, 0x10, 0x10}; // Instructions in machine language
byte temp[3];
temp[0] = 0x10;
temp[1] = 0x20;
temp[2] = 0x30;
temp = badCode;
//temp[3] == 0x42!!!
I'll add more to this later...
Ok, but that looks legit to me. Why shouldn't temp[3] = 0x42?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: TextEdit

Post by muntoo »

mattallen37 wrote:Ok, but that looks legit to me. Why shouldn't temp[3] = 0x42?
It will. BUT temp was only initialized for 3 elements (temp[0-2]). temp[3-7] have been written to. Oh oh.
On your NXT, this would probably give you a File Error, if you gave it random data. But if you gave it legitimate machine instructions, something would happen... Depends on the instructions.

I'm probably bringing about a new hacker into this world by explaining all this. ;)
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: TextEdit

Post by mattallen37 »

Ok, well, it does NOT get program errors when running, so it must be somewhat decent.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests