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 8280315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:37:56+00:00 2026-06-08T09:37:56+00:00

Why the example code below can run fine on Visual Studio. In Eclipse, NetBean

  • 0

Why the example code below can run fine on Visual Studio. In Eclipse, NetBean or CodeBlock the code can run but can’t show the Result? Thanks All.
Ex: input one string.
a/ Uppercase first letter.
b/ Remove spaces inside the string.

#include "iostream"
    #include "string.h"
    using namespace std;

    #define MAX 255

    //uppercase first letter
    char* Upper(char* input)
    {
        char* output = new char[MAX];

        bool isSpace = false;
        for (int i = 0; i < strlen(input); i++)
        {
            output[i] = input[i];
            if (isSpace)
            {
                output[i] = toupper(output[i]);
                isSpace = false;
            }
            if (output[i] == ' ') isSpace = true;
        }
        output[strlen(input)] = '\0'; // end of the string
        output[0] = toupper(output[0]); // first character to upper

        return output;
    }
    //remove space inside the string
    char* RemoveSpaceInside(char* input)
    {
        char* output = new char[MAX];
        strcpy(output, input);

        int countWhiteSpace = 0;
        for (int i = 0; i < strlen(output); i++)
        {
            if (output[i] == ' ')
            {
                for (int j = i; j < strlen(output) - 1; j++) // move before
                {
                    output[j] = output[j + 1];
                }
                countWhiteSpace++;
            }
        }
        output[strlen(output) - countWhiteSpace] = '\0'; // end of the string

        return output;
    }

    int main()
    {
        char* name = new char[MAX];
        cout << "Enter name: "; cin.getline(name, strlen(name)); 
        cout << "Your name: " << name << endl;

        cout << "\n******* Q.A *******\n";
        char* qa  = Format2VN(name);
        cout <<  qa << endl;

        cout << "\n******* Q.B *******\n";
        char* qb = RemoveSpaceInside(name);
        cout << qb << endl;
        return 0;
    }
  • 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-08T09:37:59+00:00Added an answer on June 8, 2026 at 9:37 am
    char* name = new char[MAX];
    cout << "Enter name: ";
    cin.getline(name, strlen(name));
    

    Calling strlen(name) will invoke undefined behavior, because you haven’t initialized the array. Poor strlen will try to find the NUL character in an uninitialized byte mess. Definitely not a good idea.

    What you probably want is:

    cin.getline(name, MAX);   // not sure if MAX or MAX-1 or whatever
    

    In general, do yourself a favor and replace char* with std::string. Also, get a good C++ book.

    Here is how your example would look like in actual C++:

    #include <algorithm>
    #include <cctype>
    #include <iostream>
    #include <string>
    
    std::string upper_first_letter(std::string s)
    {
        if (!s.empty()) s[0] = toupper(s[0]);
        return s;
    }
    
    std::string remove_spaces(std::string s)
    {
        s.erase(std::remove_if(s.begin(), s.end(), isspace), s.end());
        return s;
    }
    
    int main()
    {
        std::string name;
        std::cout << "Enter name: ";
        std::getline(std::cin, name);
    
        std::cout << name << '\n';
        std::cout << upper_first_letter(name) << '\n';
        std::cout << remove_spaces(name) << '\n';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to do this... I'll give example code below. But I can't
Below is a cut down example of some c# code I can't get to
The example code below works as as a server process. But when I add
(the example code below is self-contained and runnable, you can try it, it won't
for example, if i run the code below, $ProgramName is a string not a
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
Given the example source code below, is it possible for someone to see the
For this code example below, usually I would use [self fall]; instead of the
For example, I have the java code below: URL u = new URL(http://google.com); URLConnection
I have a basic PHP question, take the code below for example, let's say

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.