Computer Scientists are Pretty Pessimistic

Thursday 1 October 2015

WAP to concatenate two strings.

CODE ::

#include <stdio.h>
#include <string.h>
int main ()
{
    int i,j,k;
    char a[100],b[100],c[100];
    printf("Enter a string: ");
    gets(a);
    printf("Enter another string: ");
    gets(b);
    for(i=0;i<a[i];i++)
    {
        c[i]=a[i];
    }
    c[i++]=' ';
    for(j=i,k=0;k<b[k];k++,j++)
    {
        c[j]=b[k];
    }
    c[j]='\0';
    puts(c);
    return 0;
}


2 comments:

  1. This code is not right... :(

    ReplyDelete
    Replies
    1. This code is now right. Thanks for your feedback. :) Happy Coding :)

      Delete