473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

endless loop

This function that I have implemented gives me an infinite loop. I am
trying to produce a hexdum program, however, this function is not
functioning correctly.....Please help.

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

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

Feb 28 '07 #1
1 2629
On 27 Feb 2007 19:52:56 -0800, "uche" <ur***********@hotmail.com>
wrote in comp.lang.c++:
This function that I have implemented gives me an infinite loop. I am
trying to produce a hexdum program, however, this function is not
functioning correctly.....Please help.

void output(unsigned char ret_buffer, int curr_buffer_size, bool&
endoffile)
{
int index2=0;
int addr=0;
unsigned char outBuff[curr_buffer_size];
The line above is not valid C++ code. In C++, the size of an array
must be a compile time constant. You are using some compiler's
non-standard extension.
outBuff[curr_buffer_size] = ret_buffer;
Even assuming that you are using a non-standard extension, the line I
just pointed out defines an array of curr_buffer_size unsigned chars.
Valid elements of that array are [0] through [curr_buffer_size - 1].
So the line just above is writing one past the end of the array.
while (!endoffile)
As somebody else already pointed out, "endoffile" is passed in as a
parameter and never changes. If it is non-zero when the function is
called, this while loop will run forever.
{
cout<<setw(4)<<setfill('0')<<uppercase<<hex<<addr< <"0: "; //
prints mem location
for (int index = 0; index <16; index++)
{
index2++;
if (index2 <= curr_buffer_size)
cout<<hex<<setw(2)<<setfill('0')<<(int)outBuff[index];
else
cout<<" ";
cout<<" ";
}//end for
cout<<setfill(' ');
//cout<< " ");
index2 = 0;
for (int index = 0; index < 16; index ++)
{
index2++;
if (index2 <= curr_buffer_size)
{
if (outBuff[index] < 32 || outBuff[index] 126)
printf(".");
else
cout<<outBuff[index];
}//end if
}//end for
}
}
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2671
by: Leo | last post by:
hi all how can i terminate/stop an endless python loop which i have started inside emacs with C-c C-c. ta, leo
4
1511
by: Derek | last post by:
I am trying to refresh one datagrid after updating another datagrid. I can not call BindData for one under the other bind sub because it creates an endless loops on page load. Is there way to...
3
2846
by: John F. | last post by:
Hi all, I'm searching fulltime for days now, and I don't find the solution, so I'm thinking this is more a bug :( If i use following code in form&subforms:
30
2147
by: Skybuck Flying | last post by:
I was just trying to figure out how some C code worked... I needed to make a loop to test all possible values for a 16 bit word. Surprise Surprise... C sucks at it... once again :D lol... C is...
24
1655
by: Tweaxor | last post by:
This has been puzzling me all this week. This is actually a homework assignment from last semesmter. But the teacher wouldn't tell us why certain things didn't work, but it didn't just work. My...
13
1762
by: Bev in TX | last post by:
We are using Visual Studio .NET 2003. When using that compiler, the following example code goes into an endless loop in the "while" loop when the /Og optimization option is used: #include...
73
4536
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
1
1833
by: cory6903 | last post by:
i am having a problem with an endless loop **int x; **a: **cout << "enter a #" << endl; **cin >> x **switch(x) **{ ** case 1:
6
500
by: uche | last post by:
This function that I have implemented gives me an infinite loop. I am trying to produce a hexdum program, however, this function is not functioning correctly.....Please help. void...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.