Click here to Skip to main content
15,919,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhelp [modified] Pin
tanchinchee1-Apr-07 19:45
tanchinchee1-Apr-07 19:45 
AnswerRe: help Pin
Cedric Moonen1-Apr-07 20:35
Cedric Moonen1-Apr-07 20:35 
GeneralRe: help Pin
tanchinchee3-Apr-07 3:10
tanchinchee3-Apr-07 3:10 
GeneralRe: help Pin
Cedric Moonen3-Apr-07 7:46
Cedric Moonen3-Apr-07 7:46 
GeneralRe: help Pin
tanchinchee3-Apr-07 22:17
tanchinchee3-Apr-07 22:17 
GeneralRe: help Pin
Cedric Moonen4-Apr-07 1:04
Cedric Moonen4-Apr-07 1:04 
GeneralRe: help Pin
tanchinchee4-Apr-07 22:01
tanchinchee4-Apr-07 22:01 
GeneralRe: help Pin
Cedric Moonen5-Apr-07 0:50
Cedric Moonen5-Apr-07 0:50 
tanchinchee wrote:
Well, it turns out to be an infinite loop.


Yes, that's normal. Simply because of that:
while(n1!=n2)

What you are comparing there is two pointers (you don't compare the contents of the string but the pointers). These pointers will always point to a different address, even if the two contents are the same.

You need to compare the strings, not the addresses:
while(strcmp(n1,n2))

But as you are already doing that inside the loop, it would be better to rewrite the loop in such way:

while(strcmp(n1,n2))<br />
{<br />
  cout << "false";<br />
  infile>>n2;<br />
}<br />
cout << "true";


In fact, you will only print true when the two strings are the same so when you exit the loop.

By the way, when you post code, use the pre or code tags (just above the emoticons).


Cédric Moonen
Software developer

Charting control [v1.1]

Questionno response [modified] - why Pin
deeps_cute1-Apr-07 19:10
deeps_cute1-Apr-07 19:10 
QuestionRe: no response Pin
Hamid_RT1-Apr-07 19:51
Hamid_RT1-Apr-07 19:51 
AnswerRe: no response Pin
deeps_cute1-Apr-07 19:54
deeps_cute1-Apr-07 19:54 
GeneralRe: no response Pin
Hamid_RT1-Apr-07 20:14
Hamid_RT1-Apr-07 20:14 
GeneralRe: no response Pin
deeps_cute1-Apr-07 20:25
deeps_cute1-Apr-07 20:25 
GeneralRe: no response Pin
Hamid_RT2-Apr-07 1:01
Hamid_RT2-Apr-07 1:01 
GeneralRe: no response Pin
prathuraj2-Apr-07 17:28
prathuraj2-Apr-07 17:28 
GeneralRe: no response Pin
Hamid_RT6-Apr-07 4:15
Hamid_RT6-Apr-07 4:15 
GeneralRe: no response Pin
ThatsAlok2-Apr-07 1:35
ThatsAlok2-Apr-07 1:35 
AnswerRe: no response [modified] - why Pin
cp98761-Apr-07 20:05
cp98761-Apr-07 20:05 
QuestionMain frame and Child frame Pin
Kiethnt1-Apr-07 17:22
Kiethnt1-Apr-07 17:22 
AnswerRe: Main frame and Child frame Pin
CPallini1-Apr-07 21:01
mveCPallini1-Apr-07 21:01 
AnswerRe: Main frame and Child frame Pin
Kiethnt1-Apr-07 21:12
Kiethnt1-Apr-07 21:12 
GeneralRe: Main frame and Child frame Pin
Mark Salsbery2-Apr-07 6:05
Mark Salsbery2-Apr-07 6:05 
Questiontcp & sockets with C++ Pin
mmavipc1-Apr-07 17:06
mmavipc1-Apr-07 17:06 
AnswerRe: tcp & sockets with C++ Pin
markkuk1-Apr-07 22:22
markkuk1-Apr-07 22:22 
GeneralRe: tcp & sockets with C++ Pin
mmavipc2-Apr-07 13:13
mmavipc2-Apr-07 13:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.