?
Solved

text to image conversion

Posted on 2011-10-18
10
Medium Priority
?
282 Views
Last Modified: 2012-05-12
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(t_Image);
drawImage(m_Image);
drawImage(p_Image);
drawImage(carriage Return);
etc…
}
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 ?
Thanks
0
Comment
Question by:bachra04
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36988498
Help to do what?  Create the structure?  Create the array?  Create a pointer to the image?
0
 
LVL 2

Author Comment

by:bachra04
ID: 36988783
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
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36988947
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:bachra04
ID: 36988995
Hi

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 ?
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36989637
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?
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36989650
In C++ it is easier (IMHO) to write your own ArrayList than in C.  Do you know about Object Oriented Programming (OOP)?
0
 
LVL 2

Author Comment

by:bachra04
ID: 36990142
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)
0
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 2000 total points
ID: 36990234
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.  
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36990336
Thanks.  Hope your project goes well.
0
 
LVL 2

Author Comment

by:bachra04
ID: 36991758
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question