Hey there in this program i am passing a unsigned char** from main fuction but stream to which is the argument is not taking value plz help figure out y? -
struct BinaryData* DeFragment::defragment(unsigned char **stream, int nOfPackets)
-
{
-
int i=0,max=0,k=0,ptr=0,low=0,j,t=0,flag=0,size=0,c[3],n=1;
-
const int row=nOfPackets;
-
unsigned char *tempstr=NULL;
-
int **temp=NULL;
-
*temp=new int[nOfPackets];
-
------------------------------------------------------------------------------
-
cout<<"\n\n fucnt disp: "<<stream[0];
-
-
HERE STREAM ARRAY CONTENTS SHLD BE PRINTED BUT ITS SHOWING GARBAGE VALUES.
-
-----------------------------------------------------------------------------------
-
}
-
-
-
void main()
-
{
-
clrscr();
-
DeFragment d;
-
BinaryData *res;
-
const int nOfPackets=2;
-
////////////////////////////////////////////////////////////////////////////////////////////
-
unsigned char **stream=NULL;
-
*stream=new unsigned char[nOfPackets];
-
// stream[0]=new char[184];
-
-
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,123";
-
stream[1]="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
-
res=new BinaryData;
-
cout<<stream[0];
-
res=d.defragment(stream,nOfPackets);
-
///////////////////////////////////////////////////////////////////////////////////////////
-
if(res==NULL)
-
cout<<"Error";
-
else
-
{
-
cout<<res->bytes<<"n\n";
-
puts(res->data);
-
}
-
getch();
-
}
-
Please tell me why it is not taking the value and how I can pass the value. Please. Thank you in advance.
8 5935
Hey there in this program i am passing a unsigned char** from main fuction but stream to which is the argument is not taking value plz help figure out y? -
struct BinaryData* DeFragment::defragment(unsigned char **stream, int nOfPackets)
-
{
-
int i=0,max=0,k=0,ptr=0,low=0,j,t=0,flag=0,size=0,c[3],n=1;
-
const int row=nOfPackets;
-
unsigned char *tempstr=NULL;
-
int **temp=NULL;
-
*temp=new int[nOfPackets];
-
------------------------------------------------------------------------------
-
cout<<"\n\n fucnt disp: "<<stream[0];
-
-
HERE STREAM ARRAY CONTENTS SHLD BE PRINTED BUT ITS SHOWING GARBAGE VALUES.
-
-----------------------------------------------------------------------------------
-
}
-
-
-
void main()
-
{
-
clrscr();
-
DeFragment d;
-
BinaryData *res;
-
const int nOfPackets=2;
-
////////////////////////////////////////////////////////////////////////////////////////////
-
unsigned char **stream=NULL;
-
*stream=new unsigned char[nOfPackets];
-
// stream[0]=new char[184];
-
-
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,123";
-
stream[1]="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
-
res=new BinaryData;
-
cout<<stream[0];
-
res=d.defragment(stream,nOfPackets);
-
///////////////////////////////////////////////////////////////////////////////////////////
-
if(res==NULL)
-
cout<<"Error";
-
else
-
{
-
cout<<res->bytes<<"n\n";
-
puts(res->data);
-
}
-
getch();
-
}
-
Please tell me why it is not taking the value and how I can pass the value. Please. Thank you in advance.
modify like as follow:
unsigned char **stream=NULL;
stream=new unsigned char *[2];
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
stream[1]="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
Because stream is a pointer that point to a char* array.
thanks it worked but 1 more problem after it:-
i am trying to convert it into char* using static cast but cant :-
struct BinaryData* DeFragment::defragment(unsigned char **stream, int nOfPackets)
{
char **stream1=NULL;
stream1=new char*[2];
stream1[0]=static_cast<char*>(stream[0]);
}
getting error -
: error C2440: 'static_cast' : cannot convert from 'unsigned char *' to 'char *'
can tell me y i am getting this error or how can i do it correctly ?
thanks it worked but 1 more problem after it:-
i am trying to convert it into char* using static cast but cant :-
struct BinaryData* DeFragment::defragment(unsigned char **stream, int nOfPackets)
{
char **stream1=NULL;
stream1=new char*[2];
stream1[0]=static_cast<char*>(stream[0]);
}
getting error -
: error C2440: 'static_cast' : cannot convert from 'unsigned char *' to 'char *'
can tell me y i am getting this error or how can i do it correctly ?
You want to transform 'unsigned char * pointer into 'char * pointer, this is not correctly. although all pointer is a 32-bit number ( in 32-bit system), the scope of the data what the pointer point to is different. For example ,the CHAR
type data is from -128~127, but the unsigned char is 0~255. So the compiler
would forbid you to do that . You can only define like as follow:
unsigned char **stream1=NULL;
stream1=new unsigned char *[2];
stream1[0]=stream[0]);
but dude i have to convert it into char* by any how to perform necessary operations.
Plzz tell me how????????????
unsigned char **stream=NULL;
stream=new unsigned char *[2];
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
stream[1]="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
This is not going to work.
This syntax:
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
is initialization syntax that can be use only when the array is defined. However, it is already defined when the stream array was allocated.
You need to: -
unsigned char data0[]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
-
stream[0] = data0;
-
unsigned char data1[] ="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
-
stream[1] = data1;
-
and then your code will compile without the cast.
And I expect yopur garbage will disappear also.
Remember, you only cast in C++ when a) you are calling a relic C function, or b) when there is a flaw in your C++ design.
This is not going to work.
This syntax:
is initialization syntax that can be use only when the array is defined. However, it is already defined when the stream array was allocated.
You need to: -
unsigned char data0[]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
-
stream[0] = data0;
-
unsigned char data1[] ="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
-
stream[1] = data1;
-
and then your code will compile without the cast.
And I expect yopur garbage will disappear also.
Remember, you only cast in C++ when a) you are calling a relic C function, or b) when there is a flaw in your C++ design.
This is not going to work? You have try it?
unsigned char **stream=NULL;
stream=new unsigned char *[2];
stream[0]="0,20, 0,37, 0,1, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 65,0,75,45,34,56,4,6,89,120,200,13,55,234,255,77,1 23";
stream[1]="0,20, 0,25, 0,2, 0,44, 0,135, 192,168,0,12, 209,111,12,233, 0,0, 6,5,4,3,2";
In my opinion, Define a char * pointer, and let it point to const char array.
This is no problem. unsigned char data1[] that you define is excrescent.
but dude i have to convert it into char* by any how to perform necessary operations.
Plzz tell me how????????????
You want to convert unsigned char * into char *. This is unsafe casting. I don not know why you have to do .
This is not going to work? You have try it?
Of course I tried it. However, these are char arrays and the names of these arrays are char*. So, you have to declare an array or char*.
This won't work:
unsigned char **stream=NULL;
*stream=new unsigned char[nOfPackets];
But this will: -
unsigned char **stream=NULL;
-
stream=new unsigned char*[nOfPackets];
-
There is an article that helps understand this: http://www.thescripts.com/forum/thread772412.html.
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
11 posts
views
Thread by lokb |
last post: by
|
6 posts
views
Thread by aurgathor |
last post: by
|
16 posts
views
Thread by Ekim |
last post: by
|
5 posts
views
Thread by Stephen Cawood |
last post: by
|
6 posts
views
Thread by Bobrick |
last post: by
|
33 posts
views
Thread by Michael B Allen |
last post: by
|
11 posts
views
Thread by HSeganfredo |
last post: by
|
8 posts
views
Thread by Steven |
last post: by
| | | | | | | | | | | |