invalid types `unsigned char[int]' for array subscript

U

uche

Please give me some feed back on this issue:


Here is the complier error:
hexdmp.cpp: In function `void output(unsigned char, int, bool&)':
hexdmp.cpp:133: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:149: error: invalid types `unsigned char[int]' for array
subscript


Here is the code:

while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf('.');
else
cout<<ret_buffer[index];
}//end if
}//end for
 
R

red floyd

uche said:
Please give me some feed back on this issue:


Here is the complier error:
hexdmp.cpp: In function `void output(unsigned char, int, bool&)':
hexdmp.cpp:133: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:149: error: invalid types `unsigned char[int]' for array
subscript

Well, the first question that comes to mind is, which lines are lines
133, 146, and 149?

Post a minimal *COMPILABLE* example that exhibits the error. We don't
know the definitions of your variables, or what lines are generating the
error.

I'm guessing that it's complaining about ret_buffer[index], but without
context we can't be sure.

Here is the code:

while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf('.');
else
cout<<ret_buffer[index];
}//end if
}//end for
 
U

uche

uche said:
Please give me some feed back on this issue:
Here is the complier error:
hexdmp.cpp: In function `void output(unsigned char, int, bool&)':
hexdmp.cpp:133: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:149: error: invalid types `unsigned char[int]' for array
subscript

Well, the first question that comes to mind is, which lines are lines
133, 146, and 149?

Post a minimal *COMPILABLE* example that exhibits the error. We don't
know the definitions of your variables, or what lines are generating the
error.

I'm guessing that it's complaining about ret_buffer[index], but without
context we can't be sure.


Here is the code:
while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf('.');
else
cout<<ret_buffer[index];
}//end if
}//end for

void output(unsigned char ret_buffer, int curr_buffer_size, bool&
endoffile)
{
int index2=0;
int addr=0;

while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
133*
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
146* if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf(".");
else
149* cout<<ret_buffer[index];
}//end if
}//end for
}
}//end output
 
G

gangs

uche said:
Please give me some feed back on this issue:
Here is the complier error:
hexdmp.cpp: In function `void output(unsigned char, int, bool&)':
hexdmp.cpp:133: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:146: error: invalid types `unsigned char[int]' for array
subscript
hexdmp.cpp:149: error: invalid types `unsigned char[int]' for array
subscript
Well, the first question that comes to mind is, which lines are lines
133, 146, and 149?
Post a minimal *COMPILABLE* example that exhibits the error. We don't
know the definitions of your variables, or what lines are generating the
error.
I'm guessing that it's complaining about ret_buffer[index], but without
context we can't be sure.
Here is the code:
while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf('.');
else
cout<<ret_buffer[index];
}//end if
}//end for

void output(unsigned char ret_buffer, int curr_buffer_size, bool&
endoffile)
{
int index2=0;
int addr=0;

while (!endoffile)
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr<<"0: ";
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
133*
cout<<hex<<setw(2)<<setfill('0')<<(int)ret_buffer[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= index)
{
146* if (ret_buffer[index] < 32 || ret_buffer[index] > 126)
printf(".");
else
149* cout<<ret_buffer[index];
}//end if
}//end for
}

}//end output

Well,
unsigned char ret_buffer - you are passing a char and accessing an
array of char?
there are other compilation errors but I am sure you will be able to
get around them.

Gangs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top