Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Reading one part of a line at a time (C++ or Delphi)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Thu Jun 05, 2008 1:34 am    Post subject: Reading one part of a line at a time (C++ or Delphi) Reply with quote

I dont really know how to explain it, but lets say, i got this IP: 5.211.137.70 (my hamachi ip), and i wish to split it up, so i will get 4 "char" each containing every part of the IP, so in this case it would be:

Code:
char part1 = "5";
char part2 = "211";
char part3 = "137";
char part4 = "70";


But what i actually want to do, is to read this part from a file, where there is just written "5.211.137.70"

Is there any way to do this?
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Jun 05, 2008 2:49 am    Post subject: Reply with quote

I'm not sure about C++ but in Delphi i use .ini file(s) (IniFiles), I write/read to/from them.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Thu Jun 05, 2008 4:18 am    Post subject: Reply with quote

x0r wrote:
_tcstok.


Ty, just what i was looking for!, wondering how you understood my explination O.o
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Thu Jun 05, 2008 8:13 am    Post subject: Reply with quote

Your explanation was pretty clear.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Thu Jun 05, 2008 10:27 am    Post subject: Reply with quote

I think Delphi would be something like (this is from taking Computer Science (Pascal) in school, though I might be a bit rusty...)

Code:

var
   file : File; //or whatever that was
   i : integer;
   c : char;
   strings : array [1..4] of string;

   ...
begin
...
    for i := 1 to 4 do
    begin
        while c <> '.' do
        begin
            strings[i] := strings[i] + c;
            read(file,c);
         end;
      end;
...
end;


As I said, I am a bit rusty, so forgive me if there are any errors. Also, just to point out, it would be so much easier in C# (or any of the .NET framework Razz ):

Code:

...
    StreamReader sr = StreamReader.Null;
    string s; string[] strings;
    try
    {
          sr = new StreamReader(path);
          s = sr.ReadLine(); //this and the line below are the only things
          strings = s.Split('.'); //for the actual thing you need, everything
    } //else is just standard for IO; you don't have to do it, but it's probably
//best
    catch(Exception e)
    {
         MessageBox.Show("Exception!: " + e.ToString());
    }
    finally
    {
         sr.Close();
    }


Might be throwing code in where it doesn't belong, but oh well. Razz

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Jun 05, 2008 1:10 pm    Post subject: Reply with quote

samuri25404, yours is using what extensions ?

Here's an example of reading/writing to/from INI files in delphi:

Code:
Procedure Read_Write_INI_File;
Begin
var lol:TIniFile;
Begin
lol:=TIniFile.create(GetCurrentDir+'\lol.ini'); //Creates the ini file to current dirctory
with lol do //instead of rewriting lol. just use With/Do
begin
WriteString('General','TestText',Edit1.Text); //We write the string that is typed in a Edit1
ReadString('General','TestText',Edit1.Text); //Same as above just read it from the ini
end;
end;


If you're using a boolean type (Eg. CheckBox.Checked), use Read/WriteBool

If you're using an integer, use Read/WriteInteger
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Thu Jun 05, 2008 4:03 pm    Post subject: Reply with quote

Ty for the help all, i hoped you could do it in another way in Delphi samuri, i allready thought of that one..., but nevermind, i prefered C++ anyways Razz
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Thu Jun 05, 2008 5:26 pm    Post subject: Reply with quote

TinyXML shows a pretty decent way of reading a file with speed. take a look at that if you want for a C++ example.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites