Solved

Unsigned chars

Posted on 2003-11-18
2
309 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 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now