text to image conversion

Hi experts,
I send a linux command programmatically and get back the output :
e.g. command : ls
output : tmp\\n\\000d\\n
I’m implementing a simple text to graphic converter and basically :
I have a set of images each one corresponds to an ascii character and I will convert the output into graphic as follows:
textTographics ()
drawImage(carriage Return);
I need to load the images into an array of structures :
-      Each structure contains a pointer to the image, a charType ( t or m or p …)

I need some help on how to do that in c under linux ?
Who is Participating?
Hugh McCurdyCommented:
I wouldn't worry too much about the size unless this is for an embedded system or something else with very limited memory.   1000 pointers takes very little space in a modern PC.

You can guarantee the buffer is null terminated as follows.
Buffer [ sizeof ( Buffer ) - 1 ] = '\0';

Open in new window

If you think you have valuable data in that last position, declare Buffer to be larger.  In any event, this will guarantee the string is null terminated.  
Hugh McCurdyCommented:
Help to do what?  Create the structure?  Create the array?  Create a pointer to the image?
bachra04Author Commented:
I need to create an array of pointers to structure and fill the structure :  --> Help is needed here with C syntax under linux .
Then I need to parse the buffer and read every character :
--> I need some help there in C under linux.
For every character I need to find the corresponding structure ( I guess that’s easy no need to help there)
Finally I need to store the selected structure pointers to a a temporary list ( or array  ) : --> help needed Here
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Hugh McCurdyCommented:
I'd try something like this for the structure.  I'm going a bit from memory.  (If this doesn't work, I'll figure it out.)  This should make an array of structures of 100 elements (if I did it right).

typedef struct PicData
    <I don't know what you want in the structure>
} PicDataArray [ 100 ];

I think this actually answers your first and last question but I don't have confidence you understand.  

PicDataArray[0] should be the address of your first picture and it's in an array.
bachra04Author Commented:

Thank you for the first part

For the second part : I have a buffer of characters :

  char buffer[1024];

I need to iterate through the buffer and get the list of characters until making sure I've reached the end of the written area of the buffer

(can be e.g. only the first 10 characters and the rest of the buffer is empty)

For the third part you are suggesting that I use an array ( and not a list ) is there sthg equivalent to a list in C ?
Hugh McCurdyCommented:
By buffer, do you mean a null terminated string buffer?  If so, is the buffer guaranteed to be null terminated?  Let's say it is --

char *pCh;

for ( *pCh = Buffer; *pCh; pCh++ )
    // Do whatever processing you want on the current character here
// Do whatever processing you want after you've read the last character here.
I don't think (straight) C has a built in List.  Of course, it's possible to write your own list.  Don't know if that's such a good idea right now.

Why do you need/want a list?
Hugh McCurdyCommented:
In C++ it is easier (IMHO) to write your own ArrayList than in C.  Do you know about Object Oriented Programming (OOP)?
bachra04Author Commented:
I m thinking about a list because of the size but maybe it is easier to have an array with Max size of 1K
Regarding the buffer it is not guaranteed to be null terminated but I will try to add null after copying data to it (I don't know how but I will try)
Hugh McCurdyCommented:
Thanks.  Hope your project goes well.
bachra04Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.