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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:37:30+00:00 2026-05-22T20:37:30+00:00

I am going through some exercises and am trying to concatenate two strings using

  • 0

I am going through some exercises and am trying to concatenate two strings using only pointers (no char arrays).
My code seems to compile(Note: I am using the old 16-bit Open Watcom compiler):

#include <stdio.h>

int main(){
  char *str1 = "first";
  char *str2 =" second";

  strcat2(str1,str2);

  for(;*str1!='\0';str1++){
      printf(str1);
  }

  return 0;
}

int strcat2(char *s,char *t){
  for(;*s!='\0';s++){
    ;
  }

  while((*s++ = *t++)!='\0'){
    ;
  }

  *t++;
  t='\0';

  return 0;
}

When I tried to run it nothing happens.
I am sure my above work is horribly flawed. Any advice and help will be much appreciated.

  • 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-22T20:37:31+00:00Added an answer on May 22, 2026 at 8:37 pm

    the str1 and str2 you have declared are string literals, which cannot be modified. In linux executables the contents of the address which the str1 and str2 points to are stored in .rodata section of the executable which is not writeable. In other executables the contents are stored in a similar location which is not writeable. You should use an array or dynamically allocated memory area to do this work. Make sure when concatenating the string to which you are pasting the other string has enough space to hold both of them.

    EDIT1:

    Either do

    char str1[BUFF_SIZ] = "Hello", str2[BUFF_SIZ] = " Man";
    /* Now do strcat */ 
    /* The strlen (str1) + strlen (str2) should be lessthan BUFF_SIZ */
    

    or

    char *str1, *str2;
    str1 = malloc (sizeof (char) * BUFF_SIZ);
    str2 = malloc (sizeof (char) * BUFF_SIZ);
    strcpy (str1, "Hello");
    strcpy (str2, " Man");
    /* Now do strcat */ 
    /* The strlen (str1) + strlen (str2) should be lessthan BUFF_SIZ */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going through some pl/sql code with no comments. Trying to make sense
I was going through some code and came across a scenario where my combobox
I was going through some code that I downloaded off the internet ( Got
I am going through some example assembly code for 16-bit real mode. I've come
I'm going through some old C#.NET code in an ASP.NET application making sure that
I'm going through some old C#.NET code in an ASP.NET application making sure that
while going through some of the mili source code I came across a struct
I've been going through some old code, where I came across some custom defined
I'm going through some new code I just wrote and adding NDoc sytle comments
I'm going through some practice problems, and I saw this code: #include <stdio.h> #include

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.