Need help with data files and byte manipulation 
Author Message
 Need help with data files and byte manipulation

Hmmm...

Seems I've bitten off more than I can chew on this {*filter*} thing, so again I am
asking for help (cross-posted on rec.games.programmer)... :D

I have a data file, organized as follows:

### ### ###...
### ### ###...
### ### ###...

where three digit numbers (right justified by spaces if less than three
digits) are separated by spaces, and go 32 sets across and 32 lines down.

How do I read these numbers into a [32][32] char far *array?  I am completely
lost on this one...  Note here that the data file organization can change
(i.e. comma delimited, or whatever) but I should be able to edit it easily
from any old text editor (hence the reason I'm not using binary, although I
could, given reason enough [someone's generous source code]).

My second question is...

In QB, I had the mid$() and str$() functions, which let me combine integers
and strings:  "MAP" + STR$(mapnum) + ".MAP"    if mapnum = 5 then the
resulting string would be "MAP5.MAP".

Mid$() was used to extract a set number of bytes:  MID$("abcdefghijkl", 5, 7)  
would give me: "efghijk"  (7 bytes, starting at byte 5).

There seem to be no similar functions in Turbo C++!   Can anyone help me?  I'm
trying to load a large file into memory, and selectively read ~300k chunks
from it.  Right now, I can do that off disk with fseek and fread, but as I'm
dealing with graphics, it looks cheezed.

Thanks,
--Vito Miliano
---The Perilith Project


 \    /    _____   ___  =   Head Developer for The Perilith Project (tm)
  \  /  |    |    |   | =  
   \/   |    |    |___| =    PERILITH:  A Fantasy Spanning the World      
------------------------=               A Battle Lasting a Thousand Years



Wed, 25 Mar 1998 03:00:00 GMT  
 Need help with data files and byte manipulation

Quote:

<snip>
>>In QB, I had the mid$() and str$() functions, which let me combine integers
>>and strings:  "MAP" + STR$(mapnum) + ".MAP"    if mapnum = 5 then the
>>resulting string would be "MAP5.MAP".

>>Mid$() was used to extract a set number of bytes:  MID$("abcdefghijkl", 5,
7)  
>>would give me: "efghijk"  (7 bytes, starting at byte 5).

>You want to extract the middle characters of a string, right?
>Maybe you could use strncpy...

>        void mid(char *original, char *middle, int start, int num_chars)
>        {
>                strncpy(middle, &original[start], num_chars);
>        }

>You must be sure that start is less than the length of the original string...

Be careful.  When strlen(&original[start]) >= num_chars, strncpy will not
append a '\0' to middle.  In this case.  you will have to do it yourself.

--
John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:



Sat, 28 Mar 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. need help with file manipulation on jpg and gif

2. Need help with File and Directory Manipulations

3. Need portable/ANSI data type for 8-Bit byte

4. Abstract Data Manipulation Interface - help!

5. Abstract Data Manipulation Interface - help!

6. Need help streaming data from BMP file

7. newbie needs help with opening a data file

8. Need help with input data from file

9. NEED HELP WITH STRING MANIPULATION

10. Need help w/ C programming - string manipulation

11. Need help with font manipulation using MSC 6.0

12. Need help with variant manipulation

 

 
Powered by phpBB® Forum Software