Saturday, October 31, 2009

[Cpp-Programming] Looping to get user input causes infinite loop

Hi all,

Please bear in mind i'm a complete novice when it comes to c! I'm
building a program that gets input from the user. I am using scanf to
get a line and then do some processing and this is working fine. The
problem comes when I try to loop through this until the user enters
'quit'. It works fine the first time round but then just goes into an
infinite loop. The code is below:

while (1) {

char expr[100] = {0};

printf("Input Expression:");
scanf("%[^\n]", expr);

if (strcmp(expr, "quit") == 0) { return 0; }

// do stuff here

printf("\n");

}

This has been simplified by removing some extra code that processes
the input however I don't think this is where the problem lies. I
think it's something to do with the scanf but am unsure what. Any
pointers greatly appreciated!

Cheers,
James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en
-~----------~----~----~----~------~----~------~--~---

Monday, October 05, 2009

[Cpp-Programming] Earn Money Via Internet

Hello,

I want to tell you about great site I found. They pay me to read e-
mail,
visit web sites and much more.

It's free to join and easy to sign up! CLICK THIS
LINK TO VISIT:
http://sweetptr.com/pages/index.php?refid=fazal

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to cpp-programming@googlegroups.com
To unsubscribe from this group, send email to cpp-programming+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cpp-programming?hl=en
-~----------~----~----~----~------~----~------~--~---