Solved

Unsigned chars

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

840 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