Solved

Unsigned chars

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

832 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