By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Feb 26 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
uche wrote:
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
Feb 26 '07 #2

P: n/a
On Feb 25, 11:35 pm, red floyd <no.s...@here.dudewrote:
uche wrote:
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

Feb 26 '07 #3

P: n/a
On Feb 26, 12:55 pm, "uche" <uraniumore...@hotmail.comwrote:
On Feb 25, 11:35 pm, red floyd <no.s...@here.dudewrote:
uche wrote:
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.

Feb 26 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.