Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8717051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:13:28+00:00 2026-06-13T06:13:28+00:00

If the user inputs a sentence containing spaces the while loop stops at one

  • 0

If the user inputs a sentence containing spaces the while loop stops at one of these spaces. Why is this happening? are ‘\0’ and a space the same or did i do something else wrong?

int main ( )
{
    char user_input[200];
    cin>>user_input;
    int i=0;
    while(user_input[i]!='\0')
    {
        i++;
    }
    cout<<i;
    return 1;

}

Thanks everyone, I appreciate your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:13:29+00:00Added an answer on June 13, 2026 at 6:13 am

    \0 is the null terminating character with ASCII code 0.
    Space is another character with ASCII 32 i suppose.
    In fact you are doing this.

    cin >> user_input;
    

    It takes input till you press space or enter. So no space is present in your user_input string.
    Use this instead of cin.

    cin.getline (user_input, 200, '\0') ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user inputs a value in a certain column then this value should
How do I make this so once the user inputs a number and presses
I save user inputs (comments) in these tables. NEWS_COMMENTS - id - comment PRODUCT_COMMENTS
User inputs data in a textbox, selects GO from the menu. This launches a
When validating user inputs in an application that is to be run across multiple
I have an array of user inputs ($atts) as key=>value pairs. Some of the
I'm writing a program where the user inputs names and then ages. The program
I have a textbox where a user inputs a number, like: 105.14 When I
I am setting e.Cancel = true in _CellValidating event when user inputs invalid value
I'm trying to connect to a server that the user inputs. When the server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.