473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Indexing .txt files in c++

Hello,

although this question has probebly been answered a bunch of times i couldent find the answer im looking for.... anyways what im trying to do is....

Say i want to create a c++ program to read something from a file but i want the file to be in the following format...

File.txt
----------------------------
"Data"
{
"Data1" "546"
"Data2" "546"
"Data3" "446"
}

"Something else" "546" "43246"
"aslk" "asdh"

and so on...
----------------------------

how could i go about writing this c++ file in the simplest way possible.... yet still be efficient....

(im NOT looking for something .ini for example...
[something]
a = s;dkas
b = askjd
....)

/////////////////////////////////////////
here is an example of a program that may use this....

Calculate.exe

Numbers.txt
"First_Number" "5"
"Second_Number" "10"

OR

"add"
{
"First_Number" "5"
"Second_Number" "10"
}
/////////////////////////////////////////

thanks in advance....
Aug 1 '07 #1
3 1469
weaknessforcats
9,208 Expert Mod 8TB
If you want sonething like this:

"Something else" "546" "43246"

then write your string and be sure to write the null terminator. Then on the play back you can use getline to read into a buffer until you reach the \0 delimiter.

Method 2:

Something else

requires 14 characters.

You could write:

14Something else3546543246

Here you read first into an int (4 bytes) and that int is the string length. So you allocate 14+1 characters (that's one is for the null terminator) and read 14 bytes then tack on a \0 in the buffer and you have "Something else".

Then you read into an int (4 bytes) and allocate 3+1, etc for the "546" string.

Method 3:

Something else|546|43246|

Here the | symbol is used as a delimiter. The advantage here is you can see this character and with a text file you can create the file using an editor and read the file wioth your program.

It all boils down to the fact that you need to know the format of the file in oreder to read it.
Aug 1 '07 #2
Well needing to know the format of the file kinda eliminates of what im really trying to do....

if you look at the Half life 2 gameinfo.txt and weapon scripts (well practically the whole game definition system) you would see that there is no format and everything is very random.....

here i found a wikipedia entry to help me but im still kinda unclear about this whole topic...

http://en.wikipedia.org/wiki/Associative_array#C.2B.2B
Aug 1 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Well needing to know the format of the file kinda eliminates of what im really trying to do....
Still, you can't read a character and say: Gee, I wonder what this is part of?

You need to know how to read the file. That implies you know how it was written.

You caninvent a script so you can read one record from the file and look at the first non-blank characters to determine how to parse the rest of the record:

FILENAME= logfile.txt
PATHNAME = c:\MyGames\Game141
MOVE= A7 G10
LASER= OFF

etc...
Aug 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Martin Emanuelsson | last post by:
Hello. I have a problem with a small asp-solution that searches for documents with indexing service. For some files in the search result I get "bad text" returned, such as...
8
by: Martin Emanuelsson | last post by:
Hello, I have a problem with a small asp-solution that searches for PDF-documents with indexing service. For some files in the search result I get gibberish returned, such as...
2
by: Janiv Ratson | last post by:
Hello, I have an MFC application. In one of my screens the user need to choose a driver from a list of thousands drivers. We cannot use DB, so we use XML only. The drivers files are in the...
10
by: Lyle Fairfield | last post by:
By default mdb etc files are not searched by Indexing Service. The default can be changed in Windows XP Pro using Group Policy. I can find no suggested way to make the change in the Windows XO...
0
by: Chung Leong | last post by:
Here's a short tutorial on how to the OLE-DB extension to access Windows Indexing Service. Impress your office-mates with a powerful full-text search feature on your intranet. It's easier than you...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
1
by: manojuniverse | last post by:
Hi, I have files on remote computer which need to be indexed. I am using indexing service of my local computer to index those files but I am not able to do that. If anybody could suggest me how...
0
Cyberdyne
by: Cyberdyne | last post by:
Hi guys has anybody done indexing on a windows 2000 or windows 2003 server? I am trying to index a folder with thousands of wordperfect files, word files, pdf files, excel files and .txt files. Also...
4
by: twilliamson | last post by:
Hello, I am new to the Indexing Service and need a little help. My main goal is for my Windows XP Pro SP2 users is to be able to use the Windows Search (start, search) function to search for...
2
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.