#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char string1[20], string2[20];
int i,j,pos;
strset(string1, ‘\0′); /*set all occurrences in two strings to NULL*/
strset(string2,’\0′);
printf(“Enter the first string :”);
gets(string1);
fflush(stdin);
printf(“Enter the second string:”);
gets(string2);
printf(“First string = %s\n”, string1);
printf(“Second string = %s\n”, string2);
/*To concatenate the second string to the end of the string
traverse the first to its end and attach the second string*/
for (i=0; string1[i] != ‘\0′; i++)
{
; /*null statement: simply traversing the string1*/
}
pos = i;
for (i=pos,j=0; string2[j]!=’\0′; i++)
{
string1[i] = string2[j++];
}
string1[i]=’\0′; /*set the last character of string1 to NULL*/
printf(“Concatenated string = %s\n”, string1);
}
/*—————————————
Output
Enter the first string :CD-
Enter the second string:ROM
First string = CD-
Second string = ROM
Concatenated string = CD-ROM
—————————————-*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
- C program to read A (MxN), find the transpose of a given matrix and output both the input matrix and the transposed matrix.
- C program to read two matrices A (MxN) and B(MxN) and perform addition OR subtraction of A and B. Find the trace of the resultant matrix. Output the given matrix, their sum or Differences and the trace.
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
- C program to read in four integer numbers into an array and find the average of largest two of the given numbers without sorting the array. The program should output the given four numbers and the average with suitable headings.
