concatenate two strings! K&R problem

This is a discussion on concatenate two strings! K&R problem within the Linux Programming forums, part of the Platform Specific Boards category; Here is another problem from K&R , I have been sittin with it for 4 hours This program tried to ...

  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
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    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
    32,833
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:03 AM
  2. adding strings hard problem...
    By qubit67 in forum C Programming
    Replies: 28
    Last Post: 04-22-2007, 03: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-05-2004, 12:06 AM
  5. problem with strings (explained)
    By dune911 in forum C Programming
    Replies: 9
    Last Post: 02-11-2002, 06:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21