What is a string ? Write a function in C for string concatenation. Without the use of inbuilt string function?
What is a String? Write a function in C for string concatenation. Without the use of an inbuilt string function.
String
A string is a data type used in programmings, such as an integer and floating-point unit, but is used to represent text rather than numbers. It is comprised of a set of characters that can also contain spaces and numbers. For example, the word "hamburger" and the phrase "I ate 3 hamburgers" are both strings. Even "12345" could be considered a string, if specified correctly. Typically, programmers must enclose strings in quotation marks for the data to recognized as a string and not a number or variable name.
String concatenation in C
C program to concatenate two strings, for example, if the two input strings are "C programming," and " language" (note the space before language), then the output will be "C programming language." To concatenate the strings, we use strcat function of string.h, to concatenate without using the library function, see another program below.
C concatenate string program
#include <string.h>
int main()
{
char a[1000], b[1000];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
strcat(a, b);
printf("String obtained on concatenation: %s\n", a);
return 0;
}
The output of the program:
What do you think?
I hope, now you have a better understanding of MACROS. Comments and suggestions regarding this article are welcome.
Comments
Post a Comment