[Cpp-Programming] Re: Looping to get user input causes infinite loop
Just a thought try apending '/0' to the expr that should let compiler
know that
On Nov 1, 1:57 am, james <james.herring...@tiscali.co.uk> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
<< Home