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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:54:31+00:00 2026-05-26T12:54:31+00:00

I’ve been looking around for a solution to this, but haven’t quite found one.

  • 0

I’ve been looking around for a solution to this, but haven’t quite found one.

I’ve got a function which do some string manipulation (simplified):

void plr(char str, char *stro){
     strcpy(*stro, str);
}

My issue lies in the fact that I cannot get my result out from the function:

int main(void){
    //string and string out.
    char str[25], stro[25];
    printf("Something please: ");
    scanf("%s", &str);

    plr(str, &stro); // So basically stro would be the same as str.
    printf("Copy succesfull, %s", stro);
    return 0;
}

The whole idea is that I have the function pluralis, which would append pluralis to the string given and output it to stro. The whole string manipulation has been tested and works, if it’s inside the main(), but I simply cannot get it to work with a function and the pointer. I could obviously leave it be, but what would I learn from that.

Is there something I need to consider when it’s an array I point to, rather than a normal value of sorts.

Edit: Thanks for all the help, it has been solved. Greatly appreciated all!

  • 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-26T12:54:32+00:00Added an answer on May 26, 2026 at 12:54 pm

    No need to mess up that way with pointers 😉

    blackbear@blackbear-laptop:~$ cat prova.c
    #include <stdio.h>
    #include <string.h>
    
    void foo(char *strin, char *strout)
    {
        strcpy(strout, strin);
    }
    
    int main(void)
    {
        char a[100], b[100];
    
        printf("What's a? ");
        scanf("%s", a);
    
        printf("What's b? ");
        scanf("%s", b);
    
        foo(a, b);
    
        printf("a is \"%s\"\nb is \"%s\"\n", a, b);
    }
    blackbear@blackbear-laptop:~$ gcc prova.c
    blackbear@blackbear-laptop:~$ ./a.out 
    What's a? abc
    What's b? def
    a is "abc"
    b is "abc"
    blackbear@blackbear-laptop:~$ 
    

    Explaination:
    This works because when you use the name of an array it decays to a pointer to its first element. So foo(a, b) actually is foo(&a[0], &b[0]). So, even if a and b are arrays, passing them to a function “converts” them to a pointer.
    Quoting from here:

    When you pass an array as an argument to a function, you really pass
    a pointer to the array’s first element, because the array decays to a
    pointer.

    and, a few lines below:

    Decaying is an implicit &; array == &array == &array[0]. In English,
    these expressions read “array”, “pointer to array”, and “pointer to
    the first element of array” (the subscript operator, [], has higher
    precedence than the address-of operator). But in C, all three
    expressions mean the same thing.

    Concluding, the problem in your code is just plr‘s prototype.

    Look for array to pointer decay for more info about this phenomena. 🙂

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.