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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:50:24+00:00 2026-06-11T14:50:24+00:00

I have two .c files that I would like to compile into on executable.

  • 0

I have two .c files that I would like to compile into on executable. Having just started learning C, I’m finding it tricky to know how to transfer text as an argument between functions (which I’ve found to be incredibly simple in every other language).

Here are the two files:

Program.c

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

int main(){

char temp[40] = stringCall();
printf("%s",temp);

}

StringReturn.c

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

char[] stringCall(){

char toReturn[40] = "Hello, Stack Overflow!";
return toReturn;

}

I usually get a problem that says something like “Segmentation Failed (core dumped)” or alike. I’ve done a lot of Googling and amazing I can’t really find a solution, and certainly no simple tutorial “This is how to move text between functions”.

Any help would be 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-06-11T14:50:25+00:00Added an answer on June 11, 2026 at 2:50 pm
    char toReturn[40] = "Hello, Stack Overflow!";
    return toReturn;
    

    This is invalid, you’re returning an auto array which gets out of scope after the function returns – this invokes undefined behavior. Try returning the string literal itself (it’s valid throughout the program):

    return "Hello, Stack Overflow!";
    

    Or a dynamic duplicate of your array:

    char toReturn[40] = "Hello, Stack Overflow!";
    return strdup(toReturn);
    

    In this latter case, you’ll need to free() the string in the caller function.

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

Sidebar

Related Questions

I have files in two different directories that I would like to merge the
I have two XML files that are generated by another application I have no
I have two text files that contain columnar data of the variety position -
Hi I have two text files that each contain different information about certain structures.The
I have these two simple files that define a C++ class with a tryME
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have two files: master/newsletter1/file.html master/newsletter2/file.html newsletter1/file.html has a lot of new changes that
I have this c# web app that relies heavily on two dll files that
I have a program that compares two files. I ran visual studio analysis and
Suppose i have one folder and inside that another two files are there .

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.