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

  • Home
  • SEARCH
  • 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 749017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:23:12+00:00 2026-05-14T14:23:12+00:00

My task consists of two parts. First I have to create globbal char array

  • 0

My task consists of two parts. First I have to create globbal char array of 100 elements, and insert some text to it using cin. Afterwards calculate amount of chars, and create dedicated array with the length of the inputted text. I was thinking about following solution :

char[100]inputData;

int main()
{  

   cin >> inputData >> endl;

   int length=0;
   for(int i=0; i<100; i++)
   {
           while(inputData[i] == "\0")
           {
               ++count;
           }
   }
char c = new char[count];

Am I thinking good ?

Second part of the task is to introduce in the first program dynamically created array of pointers to all inserted words. Adding a new word should print all the previous words and if there is no space for next words, size of the inputData array should be increased twice. And to be honest this is a bit too much for me. How I can create pointers to words specifically ? And how can I increase the size of global array without loosing its content ? With some temporary array ?

  • 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-05-14T14:23:13+00:00Added an answer on May 14, 2026 at 2:23 pm

    Regardless of the rest of your question, you appear to have some incorrect ideas about while loops. Let’s look at this code.

    for(int i=0; i<100; i++) {
        while(inputData[i] == "\0") {
            ++count;
        }
    }
    

    First, "\0" is not the NUL character. It is a pointer to a string containing only the terminating NUL byte. You want '\0' instead. Assuming this change, there are still problems. Let’s work through what will happen:

    • How does a while loop work? It executes the body repeatedly, as long as the condition is true.
    • When does a while loop finish? When the condition is finally made false by executing the body.
    • What’s the condition of your loop? inputData[i] == '\0', after correction.
    • What’s the body? ++count.
    • Can ++count ever change the value of the condition? No, because it doesn’t change i.
    • So, if inputData[i] is not the NUL byte, the while loop never executes.
    • But, if inputData[i] is the NUL byte, the while loop executes forever.
    • Assuming you’ve read a proper string into inputData, then at some point inputData[i] will be NUL, and you’ll have an infinite loop.

    To count the length of a standard C string, just do this

    count = strlen(inputData);
    

    If for some reason you really have to write a loop, then the following works:

    int len = 0, 
    while (inputData[len] != '\0') {
        len++;
    }
    

    After the loop, len holds the length of the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Task : Take two text files and output 100% matches and 75% matches. Solution
My android application is consists of 20+ activities. I want to perform some task
I have a task to create a decision tree for defining a person's creditworthiness
A common task in programs I've been working on lately is modifying a text
My application consists of main message loop (GUI) and threads (Task.Factory). In the threads
I can have any number row which consists from 2 to 10 numbers. And
In another question, other users offered some help if I could supply the array
Task: For a given position in 2D array generate list of surrounding positions located
Task: Process 3 text files of close to 1GB size and turn them into
I have very little experience with asp.net and need some help with a presumably

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.