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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:59:59+00:00 2026-05-13T05:59:59+00:00

I am a newbie to C++ and learning from the MSDN C++ Beginner’s Guide.

  • 0

I am a newbie to C++ and learning from the MSDN C++ Beginner’s Guide.

While trying the strcat function it works but I get three strange characters at the
beginning.

Here is my code

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    char first_name[40],last_name[40],full_name[80],space[1];
    space[0] = ' ';
    cout << "Enter your first name: ";
    gets(first_name);
    cout << "Enter your last name: ";
    gets(last_name);
    strcat(full_name,first_name);
    strcat(full_name,space);
    strcat(full_name,last_name);
    cout << "Your name is: " << full_name;
    return 0;
}

And here is the output

Enter your first name: Taher
Enter your last name: Abouzeid
Your name is: Y}@Taher Abouzeid

I wonder why Y}@ appear before my name ?

  • 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-13T06:00:00+00:00Added an answer on May 13, 2026 at 6:00 am

    The array that you are creating is full of random data. C++ will allocate the space for the data but does not initialize the array with known data. The strcat will attach the data to the end of the string (the first ‘\0’) as the array of characters has not been initialized (and is full of random data) this will not be the first character.

    This could be corrected by replacing

    char first_name[40],last_name[40],full_name[80],space[1];
    

    with

    char first_name[40] = {0};
    char last_name[40] = {0};
    char full_name[80] = {0};
    char space[2] = {0};
    

    the = {0} will set the first element to ‘\0’ which is the string terminator symbol, and c++ will automatically fill all non specified elements with ‘\0’ (provided that at least one element is specified).

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

Sidebar

Related Questions

I'm a machine learning newbie trying to understand how Adaboost works. I've read many
I'm a newbie to Asp.net,learning from the Apress's Begining Asp.net...book.While very curious to see
I'm learning Prolog from Learn prolog now book. I'm quite newbie in prolog and
I'm a newbie in applescript. I was trying to learn it from various sources,
This is a super newbie question, I've been programming for a while, but am
I am a newbie and learning core data from scratch. I've got the coredatamodel
I'm learning F# from just a few days, so here's a newbie question: I've
Newbie still learning, been trying to search and hack code together for hours now,
I took this code from Facebook's documentation to get me started in learning how
This question is from an Objective-C newbie, so please bear with me. I'm trying

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.