Thread: Strcat question

  1. #1
    Registered User
    Join Date
    May 2005

    Strcat question

    Hello everyone, I'm new to the boards and C++ and had a quick question.

    I wrote a program for a friend in C++ that opens a file, XOR encrypts it, and outputs it to another file based on a key that a user inputs.

    I went through the tutorials found here on, and saw the part about strcat, where it says to be careful with this function as it assumes the destination string is large enough for the source string you're trying to concatenate onto the end of it.

    I also learned the same about the gets() function and am now using fgets() instead.

    My question is... Is there a safer alternative to strcat that will do the same thing that fgets does (chop off anything larger than can fit in the destination)?

    Thanks in advance.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    look up strncat(dest,source,count)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    Registered User
    Join Date
    May 2005
    Works great, thanks for the quick reply!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An interesting question about strcat
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 07-07-2009, 12:59 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM