Thread: string.h functions help plz :)

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    string.h functions help plz :)

    hi.

    i'm currently trying to make an XOR encryption program with a slight twist, but the string.h functions are intent on preventing me from completing it.

    I'm using Dev C++ cos i got it free with a book(i'm cheap...hey). Anyway my problems lie with strlen(); and strcat();

    firstly strlen(); doesn't seem to count spaces :/ is there an alternative function at all?

    secondly, strcat doesn't like me stickin a string on the end of itself. i.e strcat(string, string); is there an alternative to this?

    thanks a lot for any help

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    all of these problems are code or implementation dependant,

    >firstly strlen(); doesn't seem to count spaces :/ is there an alternative function at all?

    actuall it does

    a self alternative could be though unlike strlen it counts the null character

    int mstrlen(char* s)
    {
    for(char* p = s;*p++;);
    return p-s;
    }

    >
    secondly, strcat doesn't like me stickin a string on the end of itself. i.e strcat(string, string); is there an alternative to this?
    <

    you must have space enough to do this in the array. depending on the implementation this may work,

    // five character array big enough to hold itself twice remember to add one for the null

    char string[11] = { "5long" };

    strcat(string,string};

    ::edit:: this is really not the best way using a second string is a better alternative.
    Last edited by no-one; 03-05-2002 at 03:21 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 11:21 PM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM