472,353 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Dynamic arrays help

project is abt encrypting a txt file with an image....

in that i will to accept a txt file from the user ..this file a need to
be stored in an array...thus file size will keep on changing....and i
need to keep that array flexible but exact to the txt thats loaded or
given by the user...how to do this part

each array element will have one char of text...

then this char is converted into ASCII --> binary --> and stored in
other array..(each element will have just have one bit)..

Feb 6 '06 #1
3 1507
Nikesh wrote:
project is abt encrypting a txt file with an image....
The words you were looking fore are "about" and "text"...
in that i will to accept a txt file from the user ..this file a need to
be stored in an array...thus file size will keep on changing....and i
Why would size "keep on changing" if you load the file only once?
need to keep that array flexible but exact to the txt thats loaded or
given by the user...how to do this part
Use malloc() based on the size of the file to allocate the space you
need. If you really need to change the size of that space later on, use
realloc().
each array element will have one char of text...

then this char is converted into ASCII --> binary --> and stored in
other array..(each element will have just have one bit)..


You cannot store a char in just one bit. The Standard requires a char
to be at least 8 bits.

Hopefully, this helps you, but your post is quite confused, and I'm
still not entirely clear what you really want, and what your problem
is. You'll get more, and better help if you don't use silly word
abbreviations, and do use proper capitalisation. Also, organising your
thoughts before actually typing helps a lot.

--
BR, Vladimir

Feb 6 '06 #2
Nikesh wrote:
project is abt encrypting a txt file with an image....

in that i will to accept a txt file from the user ..this file a need to
be stored in an array...thus file size will keep on changing....and i
need to keep that array flexible but exact to the txt thats loaded or
given by the user...how to do this part

each array element will have one char of text...

then this char is converted into ASCII --> binary --> and stored in
other array..(each element will have just have one bit)..


Well you are using some interesting language to describe what you want
-- but it turns out that "The Better String Library" (Bstrlib) can do
that easily and very robustly. You basically want a dynamic array of
characters and a dynamic array of bytes. "bstrings" in Bstrlib make no
distinction between bytes and characters and treats '\0' (and any other
binary value) as a regular character; the primary preoccupation of
"bstrings" is to be a dynamically sized string. You can encrypt the
data directly either inplace, or copied or whatever you like. If you
don't have the memory for the whole txt file, you can use a bsStream
instead.

Bstrlib is open source and available here: http://bstring.sf.net/

--
Paul Hsieh
http://www.pobox.com/~qed/

Feb 6 '06 #3
"Nikesh" <ni****@gmail.com> wrote:
# project is abt encrypting a txt file with an image....
#
# in that i will to accept a txt file from the user ..this file a need to
# be stored in an array...thus file size will keep on changing....and i
# need to keep that array Flexible but exact to the txt thats loaded or
# given by the user...how to do this part

You can set up a flexible array with something like

#define Flex(T) \
\
typedef struct {T *a; int m,n;} Flex##T; \
\
Flex##T initialFlex##T(void) { \
T v = {0,0,0}; return v; \
} \
\
void freeFlex##T(Flex##T A) { \
free(A.a); \
} \
\
int lengthFlex##T(Flex##T A) { \
return A.n; \
} \
\
T* arrayFlex##T(Flex##T A) { \
return A.a; \
} \
\
T getFlex##T(Flex##T A,int i) { \
if (0<=i && i<A.n) return A.a[i]; \
else abort(); \
} \
\
Flex##T putFlex##T(Flex##T A,int i,T v) { \
if (i<0) abort(); \
if (i>=A.m) { \
A.m = 2*i+1; A.a = realloc(A.a,A.m*sizeof(T)); \
if (!A.a) abort(); \
} \
if (i>=A.n) A.n = i+1; \
A.a[i] = v; \
return A; \
}

Flex(char)
Flexchar text = initialFlexchar();
int ch;
while ((ch=fgetc(stdin))!=EOF) text = putFlexchar(text,lengthFlexchar(text),ch);
text = putFlexchar(text,lengthFlexchar(text),0);

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that.
Feb 6 '06 #4

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

Similar topics

3
by: meyousikmann | last post by:
The following code just sets up and fills a dynamic array of integers. #include <cstdlib> int main() { int* intArray = NULL; int count; ...
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course...
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory...
4
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level...
10
by: Zytan | last post by:
This article: http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithArrays11142005060354AM/WorkingWithArrays.aspx claims that "In C#, arrays...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is...
5
by: judyw | last post by:
I am trying to build a form with many options depending on each other. I purchased a script called dynamic list options with which I create arrays...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.