Well hello!

I'm having problem with reading data from notepad.. So here is what I'm trying to do.

etc.. I have notepad file "Doc" and in it there are few things: Level= 5 Cash= 100

And what I want from my program to do is to read Level and Cash and than show it in Message Box..

the main problem is that I just have no idea how to do that :D so I can't post any code :(
Thanks :)

How far can you get in the process? Can you open up a file? Do you want to read it straight out of the file into one big string to put it in the message box? Try to see how much headway you can make first and then post whatever code you've got. I assume since you want a messagebox that you are familiar with MFC?

i think u should make a format of your DOC file like

level = 5
cash = 100

now read 1 line from the file
(Reference for reading from file is http://www.cplusplus.com/reference/clibrary/cstdio/fread/)

and then search for "=" character (use strchr function for string searching) and then pick level value.

then read the second line and get the cash value. now u have a record of cash and level . Do what you want.

1 suggestion is try to make a habit of google search.

@ adcodingmaster
I acctualy already saw that link http://www.cplusplus.com/reference/clibrary/cstdio/fread/ just needed little help to make it work.. thanks I'll try it..

@ jonsca
Well I said messagebox because it was first on my mind.. And I don't want to read it in a one big string but to separate it.. Level separately and cash separately.

So far I know how to open file and close it.. only reading part is problem..

And here's the code for opening I made..

#include <stdio.h>
.
.
.
.
// when do something ->

FILE * file;
file = fopen ("Doc.txt","r");
if (file!=NULL)
{    
    // Read from file
    fclose (file);
}

And example of Doc.txt :

Level= 5
Cash= 50

If you're doing C++ you should use fstream, it makes things a lot more intuitive, I think.
If you had no space between level and = you could have something like

ifstream infile("Doc.txt");
while(infile >> tempstring)
{
         //add tempstring to vector or array
         infile >> tempvalue;
         //add tempvalue to it's own array or vector
} //this way you can read in as many lines as you need to
//you'd have to specify the array size before hand or ask the user for 
//how many records

So, if you want to stick with the C style of doing it that's still ok, just wanted to offer the option to you.

Thank you both! I'll try it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.