Thread: Stop a while/for loop when the user inputs a string

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    14

    Stop a while/for loop when the user inputs a string

    Hello,
    How can i break a for/while loop when the user enters a specific string?

    In the main function, I ask the user to enter 10 strings and the programm should stop when the user enters for example the word 'apple'

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    if ( strcmp(input,"apple") == 0 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 01-28-2015, 11:35 PM
  2. Replies: 28
    Last Post: 12-01-2013, 12:05 PM
  3. How to handle inputs if the user inputs the wrong thing
    By bassist11 in forum C Programming
    Replies: 5
    Last Post: 09-22-2010, 04:28 AM
  4. Average of user inputs (in a loop)
    By SilentPirate007 in forum C Programming
    Replies: 13
    Last Post: 03-08-2010, 06:46 PM
  5. User inputs two characters and...
    By dre in forum C Programming
    Replies: 6
    Last Post: 09-18-2009, 01:51 PM

Tags for this Thread