Skip to main content

Thread: [C++] Convert and then convert again and ...


hello everybody,

having problem (or lots of type) finding working way convert char(s) bytef type (used zlib).

kind of new c++ programing , syntax might missing obvious.

anyhow, here program:
code:
#include <iostream> #include <zlib.h>  using namespace std;  void _compress(unsigned char & in_data, size_t in_size, unsigned char & out_data, size_t out_size){  z_stream z;  int status;      z.avail_in = 0;     z.next_out = &out_data;     z.avail_out = out_size;          if ( z.avail_in == 0 ) {             z.next_in = &in_data;             z.avail_in = in_size; //dfjngdfng         }         if ( z.avail_in != 0 )             status = deflate( &z, z_no_flush );         int count = out_size - z.avail_out;  }     int main(){     unsigned char a[100];//13     a=reinterpret_cast<unsigned char>("hello world!");     unsigned char b[100];     _compress(*b,13,*b,100);     cout << b << endl;     return 0; }
my goal make easy-to-use function compress (and later de-compress) buffer.

error last compilation attempt is:
code:
sakishrist@sakishrist-laptop:~/desktop/c++/zlib$ g++ zlib.cpp -o zlib_c -lz zlib.cpp: in function ‘int main()’: zlib.cpp:42:50: error: cast ‘const char*’ ‘unsigned char’ loses precision zlib.cpp:42:50: error: incompatible types in assignment of ‘unsigned char’ ‘unsigned char [100]’
i tried many different things of them fail. think (i can wrong many errors) know how use * , & in general.

hope can give me piece of advice.

in advance!!!

it's going wrong here:
code:
    unsigned char a[100];//13      a=reinterpret_cast<unsigned char>("hello world!");
first define array of 100 chars.
have string, , reinterpret unsigned char , try assign array.
in c++ it's impossible assign array, places in array. however, if want character array same string, have 1 character @ time, this:
code:
unsigned char a[100];  std::string hello = "hello world!";  (size_t = 0; < 100; ++i)      a[i] = < hello.size() ? hello[i] : 0;
or @ definition time, this:
code:
unsigned char a[] = "hello world!";
also, in c++ "hello world!" pointer array of characters terminated 0 byte. if reinterpret pointer (which 4 or 8 bytes long depending on processor type) char 1 byte long, drop 3 or 7 bytes, compiler complaining about.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] [C++] Convert and then convert again and ...


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support