Thread: strcat the inside of a structure

  1. #1
    Registered User
    Join Date
    Oct 2005

    strcat the inside of a structure

    i want to concatenate a string to a structure passed in the parameter and return the new structure. and it works if i pass it by reference and use pointers,

    for example,

    typedef struct
        char someString[80];
    int main
        someStruct blah;
        /*etc assignments to blah*/
        someStruct more(someStruct blah);
        return 0;
    someStruct more(someStruct blah);
        someStruct value;
        char aLine[80] = "Heya person.";
    And what I'd like to do is

    strcat(blah.someString, aLine);
    strcat(more.someString, blah.someString);

    But I get compiling issues. I understand that strcat concatenates a string to a pointer, meaning I can't just use blah.someString or more.someString, so I am now wondering how I'd be able to get around that issue but using something other than strcat(). Any ideas?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    strcat(, "something" ); /*directly*/
    strcat( foo->bar, "something" ); /*via a pointer*/

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2005
    I understand how to use the pointer option, but I want to change the actual value without having to use it.

    I get compiling issues if I do,

    strcat(, "string");

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    It's easier to start from a real example rather than a paraphrased one.
    #include <stdio.h>
    #include <string.h>
    struct type
        char text[80];
    struct type foo(struct type copy)
       struct type newobj;
       strcpy(newobj.text, copy.text);
       strcat(newobj.text, "strcat ");
       return newobj;
    int main(void)
        struct type a = {"start "};
        struct type b = foo(a);
        struct type c = foo(b);
        return 0;
    /* my output
    start strcat 
    start strcat strcat 
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing pointer to a structure in a function
    By steve1_rm in forum C Programming
    Replies: 5
    Last Post: 02-03-2008, 02:48 AM
  2. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  3. Problem with arrays inside a structure
    By babu in forum C Programming
    Replies: 4
    Last Post: 07-12-2007, 09:35 AM
  4. Structure inside Structure
    By tdep in forum C Programming
    Replies: 11
    Last Post: 07-05-2007, 08:23 AM
  5. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 06:17 AM