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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:27:47+00:00 2026-06-14T20:27:47+00:00

Alright I know that malloc or calloc can be used for dynamic allocation but

  • 0

Alright I know that malloc or calloc can be used for dynamic allocation but as a new to C I don’t know how to use that memory I allocated for inputting multiple inputs like in example of TC++ we have this code

#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include <process.h>

int main(void)
{
   char *str;

   /* allocate memory for string */
   if ((str = (char *) malloc(10)) == NULL)
   {
      printf("Not enough memory to allocate buffer\n");
      exit(1);  /* terminate program if out of memory */
   }

   /* copy "Hello" into string */
   strcpy(str, "Hello");
    /* display string */
    printf("String is %s\n", str);
    /* free memory */
   free(str);

   return 0;
}

In thus code we place Hello to memory we allocated now that should leave us with 4 more character spaces what we should do to add data to those spaces as well.

I want to implement this idea when the user is asked about number of inputs and he lets say 10 or 100 then the program inputs the data and stores them and print that data to screen.

  • 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-14T20:27:49+00:00Added an answer on June 14, 2026 at 8:27 pm

    If you want to append to your malloced string, use strcat

    str = malloc(20);
    ...
    /* copy "Hello" into string */
    strcpy(str, "Hello");
    strcat(str, ", world!");
    /* display string */
    printf("String is %s\n", str); /* will print 'Hello, world!' */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm new to VBA but I know this has to be possible. I
Alright I know that the .closest() have been discussed before, but I have been
I know that there are some similar questions, but the answers from there don't
Alright I know this is more than likely a amateur question but I have
Alright, i dont know how to explain it well.. but i have a switch
Alright, so I know about the Settings.Properties.Default.* Stuff, but thats not what im trying
Alright, I know this question has been asked before, but mine has a different
Alright, I know questions like this have probably been asked dozens of times, but
Alright, I know my title is a little obscure but it best describes the
Alright, I know that Scala allwos no aux cons type params. What if I

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.