Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to use the word exit to break from a while statement 1

Status
Not open for further replies.

ggreg

Programmer
Mar 9, 2001
201
0
0
US
how can I write code to break from a while statement using the
word exit...... in a char array that is use to enter names
I had been trying
while (trans.name !="exit")
but it will not end my loop...if I can not use exit because it is a char array
what does anyone suggest I use to break from my loop and how do I write the code?

thanks
 
maybe try:

if (strcmp(trans.name, "exit") == 0)
break;

if it is a char * string this should work.
 
More detail:

#include <string.h>
...

while (1)
{

if (strcmp(trans.name, &quot;exit&quot;) == 0)
break;

else
{
// your code
}

}
 
jtm111

your second code work perfectly!!!!! Great!!!!
thanks a bunch!!!!!!!!!!!!
 
I'd rather write :
while (strcmp(trans.name, &quot;exit&quot;) != 0)
{
// my code
}
or
do {
// My code
} while (strcmp(trans.name, &quot;exit&quot;) != 0);

but it's hair cutting...;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top