Thread: strcpy() and strcat()

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    strcpy() and strcat()

    Hi,
    I don't want to include '\0' when copying or concatinating strings. How to do that?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well, you could just ignore it or replace it with something else. Though without it, you'll be unable to perform any string operations on that string.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Code:
    strcpy(tomv, "AB ");
    strcat(tomv,l);
    strcpy(tomv, " CD");
    printf(tomv);
    for this code I want to print all strings in one line

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    One line? What? Are you sure you aren't mixing up '\n' and '\0'? The null character has nothing to do with new lines.

    You should also check your syntax as well because it's very wrong. Even on the printf().
    Code:
    char foo[13];
    strcpy(foo, "Hello ");
    strcat(foo, "World!");
    printf("%s",foo);
    
    /* 
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    
    C:\Dev-Cpp>hworld
    Hello World!
    */
    Last edited by SlyMaelstrom; 07-03-2006 at 01:09 AM.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Quote Originally Posted by SlyMaelstrom
    One line? What? Are you sure you aren't mixing up '\n' and '\0'? The null character has nothing to do with new lines.

    You should also check your syntax as well because it's very wrong. Even on the printf().
    Code:
    char foo[13];
    strcpy(foo, "Hello ");
    strcat(foo, "World!");
    printf("%s",foo);
    Ohhh, . Sorry, I mean \n

    Sorry again

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You'll have to either remove the '\n' before copying or use something like strncat() to only copy a certain number of character. If you use strncat() remember to manually terminate the finished string after the copy.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. argv change
    By dracayr in forum C Programming
    Replies: 9
    Last Post: 04-10-2009, 02:49 AM
  2. problem in my strcpy strcat function
    By genie in forum C Programming
    Replies: 7
    Last Post: 11-07-2008, 09:36 AM
  3. Replies: 2
    Last Post: 06-03-2008, 12:57 AM
  4. strcat - strcpy
    By pizzas in forum C Programming
    Replies: 4
    Last Post: 08-05-2003, 02:11 AM
  5. strcat or strcpy?
    By dirgni in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2002, 12:10 PM