Thread: concatenate two strings! K&R problem

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    8

    concatenate two strings! K&R problem

    Here is another problem from K&R , I have been sittin with it for 4 hours

    This program tried to concatenate two strings. It aint doin it


    Code:
    #include "stdio.h"
    
    int  str_cat(char *, char *);
    
    int main()
    {
            char *str1 = "saguna";
            char *str2 = "karan";
             str_cat(str1,str2);
            return 0;
    } //main closes
    
    int   str_cat(char *st1, char *st2)
    {
            for(; *st1 != '\0'; st1++)
            {
                    if(*st1 == '\0')
                    {
                            printf("check ");          //not goin in if statement, it goes till s
                            for(;*st2 != '\0';st2++)
                            {
                             *st2 == *st1;
                            }
                            printf("The value of *st2=\n\n\n\n\n%c",*st2);
                             //return *st2;
                    }
                    else
                    {
                            printf("\nsomethings wronng\n");
                    }
            }
    } //str_cat closes

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    I think you've already posted this. Please don't double-post.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Agreed - closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! Problem with strings
    By fragrax in forum C Programming
    Replies: 6
    Last Post: 07-03-2008, 10:03 AM
  2. adding strings hard problem...
    By qubit67 in forum C Programming
    Replies: 28
    Last Post: 04-22-2007, 02:02 AM
  3. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 11:47 PM
  4. getchar() problem from K&R book
    By anemicrose in forum C Programming
    Replies: 13
    Last Post: 04-04-2004, 11:06 PM
  5. problem with strings (explained)
    By dune911 in forum C Programming
    Replies: 9
    Last Post: 02-11-2002, 06:02 PM