473,387 Members | 1,582 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,387 software developers and data experts.

Connect two pointers (arrays)

Hi!
As the subject says i want to connect two binarys arrays with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..

Regards,
Pascal
Nov 14 '05 #1
6 2652

"Pascal Ehlert" <da****@dadark.de> wrote in message
news:20041010212738.5d434460@localhost...
Hi!
As the subject says i want to connect two binarys arrays
Please specify what you mean by 'binary array'.
with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..


Do you simply want to append data to an existing array?
Do you want to cause two separate arrays to become
adjacent in memory, or what?

-Mike
Nov 14 '05 #2
Pascal Ehlert wrote:
Hi!
As the subject says i want to connect two binarys arrays
What is a binary array ?

with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..


strcat is defined primarily for C-strings , whereas
fread can read any kind of data from files.
Also, if you are going to read a chunk of characters
using fread, it is not going to
insert the null character at the end for you.
Think about these aspects and post some compilable
code to get more help.

--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '
Nov 14 '05 #3
"Mike Wahler" <mk******@mkwahler.net> wrote:

"Pascal Ehlert" <da****@dadark.de> wrote in message
news:20041010212738.5d434460@localhost...
Hi!
As the subject says i want to connect two binarys arrays
Please specify what you mean by 'binary array'.

The data which was read out by fread.. I don't know how to call it.
with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..


Do you simply want to append data to an existing array?

Yes, that's what I want.. Like strcat does it. :-) Do you want to cause two separate arrays to become
adjacent in memory, or what?

Pascal
Nov 14 '05 #4
Pascal Ehlert <da****@dadark.de> wrote:
As the subject says i want to connect two binarys arrays with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..


There is no such thing, and there can be no such thing, for the simple
reason that it is not possible to deduce from the contents of binary
data where it ends. strcat() works by looking for the '\0' that
terminates the first string. This doesn't work for binary data, since
there is no such marker, and cannot be; after all, any byte that you use
for an end marker could just as well be valid binary data. In
particular, a byte with value 0 is often a normal part of binary data,
and cannot be used to terminate it; but neither can any other value.

To get around this problem, you'll simply have to remember how many
bytes you read, do a little pointer addition, and use memcpy().

Richard
Nov 14 '05 #5

"Pascal Ehlert" <da****@dadark.de> wrote in message
news:20041011181514.6220d434@localhost...
"Mike Wahler" <mk******@mkwahler.net> wrote:

"Pascal Ehlert" <da****@dadark.de> wrote in message
news:20041010212738.5d434460@localhost...
Hi!
As the subject says i want to connect two binarys arrays


Please specify what you mean by 'binary array'.

The data which was read out by fread.. I don't know how to call it.


OK, I think you're reading from a file which was opened in
'binary mode', i.e. 'fopen()'s second argument of "rb", and
passign 'fread()' an pointer to your array
with content read out by fread.
Easy: I'm looking for a strcat function which works on binary..


Do you simply want to append data to an existing array?

Yes, that's what I want.. Like strcat does it. :-)


Well you can't do it 'like strcat() does it' (unless you can
guarantee your file does not contain any characters with value
zero).

If you can make this guarantee:
Before you open the file, set the array element where you
want to start appending to zero. Then before each read,
search for that zero, pass its address to fread(), after
fread is done, set the array element after the read data
to zero. Keep doing this until you have all the data you
want, or end of file.
But all that isn't necessary. fread() will tell you (via
its return value) how many items were read (in the case
of characters, this is the same thing as bytes -- see
fread documentation for further details.) You can use this
information to specify the address (i.e. fread's first argument)
for subsequent calls to fread.

Finally remember to ensure that your array is large enough
to accomodate all the desired data.

-Mike


Nov 14 '05 #6
Pascal Ehlert wrote:
Hi!
As the subject says i want to connect two binarys arrays with
content read out by fread.
That makes about as much sense as your subject.
Easy: I'm looking for a strcat function which works on binary..

lol, memcpy?
Regards,
Pascal


Rob Gamble

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
11
by: Linny | last post by:
Hi, I need some help in declaring an array of pointers to array of a certain fixed size. I want the pointers to point to arrays of fixed size only (should not work for variable sized arrays of the...
79
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The...
6
by: Carl-Olof Almbladh | last post by:
Already in the 1st edition of the "White book", Kerigham and Ritchie states the "C is a general purpose language". However, without what is usually called "assumed size arrays" and built-in...
4
by: Richard Hayden | last post by:
Hi, Why does gcc (3.3.2) give me a 'initialization from incompatible pointer type' warning when compiling: int main(int argc, char** argv) { int testa; int** testp = testa; }
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
36
by: raphfrk | last post by:
I have the following code: char buf; printf("%lp\n", buf); printf("%lp\n", &buf); printf("%lp\n", buf); printf("%lp\n", buf); printf("%d\n", buf-buf);
6
by: joelperr | last post by:
Hello, I am attempting to separate a two dimensional array into two one-dimensional arrays through a function. The goal of this is that, from the rest of the program, a data file consisting of...
8
by: Piotrek | last post by:
Hi, Like almost all of beginners I have problem understanding pointers. Please, look at this piece of code, and please explain me why myswap function doesn't work as it's supposed to do, whereas...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.