Solved

Unsigned chars

Posted on 2003-11-18
2
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

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 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…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

617 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