code for concatination of 2 strings with out using library
functions?

Answers were Sorted based on User's Feedback



code for concatination of 2 strings with out using library functions?..

Answer / kiruthikau

[code]
#include<stdio.h>
#include<string.h>
main()
{
char one[]="hai";
char two[]=" hello";
int len1=strlen(one);
int len2=strlen(two);
char res[len1+len2];
int i,j;
for(i=0;i<len1;i++)
res[i]=one[i];
for(j=0;j<len2,i<len1+len2;i++,j++)
res[i]=two[j];
res[i]='\0';
printf("res:%s\n",res);
}
[/code]

If you don't want to use strlen() function also ,try the
following code.

[code]
#include<stdio.h>
#include<string.h>
main()
{
char one[]="hai";
char two[]=" hello";
int len1=0;
int len2=0;
int i=0;
int j;
while(one[i++]!='\0')
len1++;
i=0;
while(two[i++]!='\0')
len2++;
char res[len1+len2];
for(i=0;i<len1;i++)
res[i]=one[i];
for(j=0;j<len2,i<len1+len2;i++,j++)
res[i]=two[j];
res[i]='\0';
printf("res:%s\n",res);
}
[/code]

Is This Answer Correct ?    5 Yes 1 No

code for concatination of 2 strings with out using library functions?..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void strrcat(char *,char *);
void main()
{
char a[50],b[50];
int i;
clrscr();
printf("enter the string 1 :");
gets(a);
printf("enter the string 2 :");
gets(b);
strrcat(a,b);
gets(a);
getch();
}

void strrcat(char *a , char *b)
{
for(int i=0;*a!='\0';i++,a++);
for(int j=0;*b!='\0';j++,i++,b++,a++)
*a=*b;
*a='\0';
}

thank u :)

Is This Answer Correct ?    0 Yes 0 No

code for concatination of 2 strings with out using library functions?..

Answer / chavidi

void main()
{
char a[20],b[20];
int i,j,k;
gets(a);
gets(b);
i=strlen(a);
k=i+strlen(b);
j=0;
while(i<=k)
{
a[i]=b[j];
i++;
j++;
}
printf("Resultant String is %d :",a);
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is the use of keyword VOLATILE in C?

1 Answers  


Why c is a mother language?

0 Answers  


#define MAX 3 main() { printf("MAX = %d \n",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif

4 Answers   IBM, Vector,


What does 1f stand for?

0 Answers  


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

0 Answers   Wipro,






Explain what are the different file extensions involved when programming in c?

0 Answers  


What is pass by reference in functions?

0 Answers  


CAN ANYONE PLEASE HELP ON THIS PROGRAM FOR MY EXAM..TQ Write a C program to help a H’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the H’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the H’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80 Your program must do the following task below: a. Define the data structs, menu item types with two components: menu item of type string and menu price of type double. Use an array to declare the data structs. b. Function get data to loads the data into the array menu list. c. Function show menu to show the different breakfast items offered by the restaurant and tell the user how to select the items. d. Function print receipt to calculates and prints the customer receipt. The billing amount should include a 5% tax. e. Format your output with two decimal places. The name of each item in the output must be left-justify. You may assume that the user selects only one item of a particular type. f. The two sample output as shown: Welcome to HiFi’s Restaurant 1 Bacon and Egg $3.45 1 Muffin $2.20 1 Coffee $1.50 Tax 5% $0.35 Amount Due $7.50

1 Answers  


#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(“%d\n”, ++*I); Printf(“%d\n”, *++I); Printf(“%d\n”, (*I)--); Printf(“%d\n”, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300

4 Answers   Tieto,


how to create duplicate link list using C???

0 Answers  


we compile c program in 32 processor and 64 bit processor .exe file is created in both the processors. if we want to run .exe file in 64 bit processor which is created in 32 bit processor. is that .exe file is run or not if it is not run why?

4 Answers   HP, Wipro,


find the sum of two matrices and WAP for it.

0 Answers   Huawei,


Categories