Thread: strcat program

  1. #1
    Registered User
    Join Date
    Jul 2003

    strcat program

    i read C Programming Language chapter 2-2.8 and wrote a strcat program
    #include <stdio.h>
    void cat(char s[],char t[]);
    char s[]="Hello ";
    char t[]="World";
    void cat(char s[],char t[])
    int i,j;
    while(s[i] != '\0')
    while((s[i++]=t[j++]) != '\0');
    when i try to compile using gcc i get
    In function `main':
    11: invalid use of void expression
    Why is that invalid?
    then i replace void cat(... with int cat(... and it compiles but when i run it , it prints crap like

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Should be int main(void)

    This means you want to print the string that cat returns, but you have cat set to return void

    >void cat(char s[],char t[])
    This should be char* vat(char[], chart[])

    Then you need to return s at the end of cat

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User
    Join Date
    Jul 2003


    thanks a lot , it works fine now

  4. #4
    Registered User
    Join Date
    Jul 2003
    I'm sure that it appears to work just fine, but you still have a rather serious problem. Turn back to the last paragraph on the previous page (47) which says in part: "strcat assumes that there is enough space in s to hold the combination." Is there?

    Hint: how large is the array 's' in main? How big does an array need to be to hold "Hello World" plus a '\0' terminator?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM