Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unsigned chars

Posted on 2003-11-18
2
Medium Priority
?
326 Views
Last Modified: 2010-04-15
Part of code taken from small JPEG Code Library by Rich Geldreich

bool tga_writer::write_line(const void *Pscan_line)
{
  uchar *Psb = (uchar *)Pscan_line;
      
  if (!Pfile)
    return (true);

  if (fwrite(Pscan_line, bytes_per_line, 1, Pfile) != 1)  // bytes_per_line = 681, in this case
    return (true);

  return (false);
}


// Definition given in header file
typedef unsigned char  uchar;       /*  8 bits     */

in main
=======

uchar *Pdb = Pbuf;

status = Pdst->write_line(Pbuf); // status if of type boolean

My question is
1. how can I assign the contents of Pbuf (within main program) or Pscan_line within

   bool tga_writer::write_line(const void *Pscan_line)

to say an array (1-D or 2-D) so that I can manipulate the contents.

0
Comment
Question by:baharbh
  • 2
2 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9770228
>1. how can I assign the contents of Pbuf (within main program) or Pscan_line within

>   bool tga_writer::write_line(const void *Pscan_line)

>to say an array (1-D or 2-D) so that I can manipulate the contents.


bool tga_writer::write_line(const void *Pscan_line)
{
 char array [MAX_LINE_LENGTH];
 uchar *Psb = (uchar *)Pscan_line;
   
  if (!Pfile)
   return (true);

  memcpy ( array, Pscan_line, bytes_per_line );     //now your line is in 1D array

 if (fwrite(Pscan_line, bytes_per_line, 1, Pfile) != 1)  // bytes_per_line = 681, in this case
   return (true);

 return (false);
}
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 9770251
if MAX_LINE_LENGTH is not know in advance, you can proceed like this


bool tga_writer::write_line(const void *Pscan_line)
{
uchar * array ;            ========== i wrote char in previous post ... correct it
uchar *Psb = (uchar *)Pscan_line;
   
 if (!Pfile)
  return (true);

 array = (uchar *) malloc ( sizeof (uchar) * bytes_per_line );

 memcpy ( array, Pscan_line, bytes_per_line );     //now your line is in 1D array

if (fwrite(Pscan_line, bytes_per_line, 1, Pfile) != 1)  // bytes_per_line = 681, in this case
  return (true);

return (false);
}

also this is C++ and not C ... we have a separate forum for C++
http://oldlook.experts-exchange.com/Programming/Programming_Languages/Cplusplus/
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

773 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