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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:40:23+00:00 2026-05-26T07:40:23+00:00

Disclosure: This is university work. I am not expecting code to accomplish my task

  • 0

Disclosure: This is university work. I am not expecting code to accomplish my task rather I want to understand how best to manipulate strings in C.

I need to write a function to manipulate a string in a certain way (I’m not saying what so as to ensure that no-one provides exact code).

In python I’d just do the following

def foo(str):
  return str

Clearly things aren’t as easy as that in C.

Can anyone tell me how best to achieve this. Should I use pointers to simulate passing by reference and just manipulate the original string? Any help / resources would be greatly appreciated.

Update: I do want to preform an operation on the string and return the result of that operation (also a string). I am happy to manipulate the original string or return it. Which ever would be considered best practice.

The task I’ve been set is based on how to do that operation so I didn’t want to make that explicit.

So the Python would be:

def foo(str):
  #do something to str (which doesn't change it's length)
  return str
  • 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-26T07:40:24+00:00Added an answer on May 26, 2026 at 7:40 am

    There are two ways:

    1. If you manipulate the original string you don’t need to return anything
    2. If you don’t want to change the original string you should copy it with strdup or malloc + strcpy and return a pointer (char *) to it. The caller of course must free it when done.

    It all rests on the question: will the caller need the original string ?

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

Sidebar

Related Questions

First, in order to provide full disclosure, I want to point out that this
DISCLOSURE: This is homework. The code below is meant to read a command file
I have this old jquery script for progressive disclosure: (notice the $(this).text('more...') code changes
full disclosure - this is for a homework assignment. And I normally would not
Full disclosure : This is for a homework assignment. This is driving me nuts.
How would you define testing? In the interest of full disclosure, I'm posting this
First, some disclosure: I am not a Linux admin, and my Linux admin is
First off, full disclosure: This is going towards a uni assignment, so I don't
I want to add an annotation to a MapView with disclosure button on it
Full disclosure: this issue is duplicated on the ggplot2 google group I'm developing a

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.