C: Trying to do some simple things in C and i just can't get them to work

Discussion in 'OT Technology' started by zanyspy_dude, Sep 8, 2007.

  1. zanyspy_dude

    zanyspy_dude King of teh n00bz

    Joined:
    Aug 29, 2002
    Messages:
    4,473
    Likes Received:
    0
    Location:
    Indianapolis, IN
    basically i have no idea how to cat strings together to start with.

    i have this function

    char *lookupPath(char *name)
    {
    ...

    return "error" + name + "was not found.\n";


    }

    How do i really do this?
     
  2. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    The strcat() function from string.h is used to concatenate strings, but snprintf() is better suited for what you want to do.

    static char buf[80];

    snprintf(buf, 80, "error %s was not found.\n", name);

    return buf;
     
  3. zanyspy_dude

    zanyspy_dude King of teh n00bz

    Joined:
    Aug 29, 2002
    Messages:
    4,473
    Likes Received:
    0
    Location:
    Indianapolis, IN
    so how do i use strcat() to do it? I also need to do this, which i think strcat would do:


    access(dirs[counter] + name, X_OK);
     
  4. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    This is a homework assignment, isn't it. :squint:
     
  5. rioter

    rioter New Member

    Joined:
    May 4, 2004
    Messages:
    3,811
    Likes Received:
    0
    i dont think snprintf is standard is it?
    so either strncat (safer version of strcat) or sprintf is the way to go.
     

Share This Page