code for copying two strings with out strcpy() function.

Answers were Sorted based on User's Feedback



code for copying two strings with out strcpy() function...

Answer / suman_kotte

#inclue<stdio.h>
main()
{
char str1[10],str2[10];
int i=0;
printf("enter the str1");
gets(str1);
while(str1[i]!='\0')
{
str2[i]=str1[i];
i++;
}
puts(str2);
}

Is This Answer Correct ?    19 Yes 2 No

code for copying two strings with out strcpy() function...

Answer / ali

#include<iostream.h>
void main(void)
{
char first[]="sajid";
char second[6];
int index;
for(index=0;index<6;index++)
{
second[index]=first[index];
}
cout<<second;
}

Is This Answer Correct ?    8 Yes 6 No

code for copying two strings with out strcpy() function...

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void str_cpy(char *,char *);
void main()
{
char a[30],b[20];
printf("enter the string to be copied :");
gets(b);
str_cpy(a,b);
printf("the final string is :");
puts(a);
getch();
}
void str_cpy(char *a,char *b)
{
if(*b!='\0')
{
*a=*b;
str_cpy(++a,++b);
}
*a='\0';
}

thank u

Is This Answer Correct ?    6 Yes 4 No

code for copying two strings with out strcpy() function...

Answer / reachhary

well, we could also have a string accepted at run time by
use of scanf.

To take care of such cases.

char *mystrcpy(char src[])
{
char *dest = NULL;
int indx = 0, len = 0;
if (!src) return dest;
len = strlen(src);
dest = (char *)malloc(sizeof(char) * len + 1);
while (; src[indx] ; dest[indx++]=src[indx]);
dest[indx]='\0'
return (dest)
}
Please do update if any one finds any issue with the code
segment - in terms of any error or any optimisation

Is This Answer Correct ?    3 Yes 3 No

code for copying two strings with out strcpy() function...

Answer / rohit

#include<iostream>
using namespace std;
int main()
{
int i;
char str1[10]="rohit";
char str2[10]="sinsinwar";
void strcpy(char,char);
cout<<str2;
return 0;
}
void strcpy(char str1[],char str2[])
{
int i=0;
while(str1[i]!='\0')
{
str2[i]=str1[i];
i++;
}
str2[i]='\0';
}
//whats the problem in this code...would u please suggest asap..

Is This Answer Correct ?    1 Yes 1 No

code for copying two strings with out strcpy() function...

Answer / ankitecian

int main(int argc, char *argv[])
{
char _output[200];
memset(_output,'\0',200);
if(argc < 2)
{
printf("Usage: <%s> <String -1>\n",argv[0]);
return -1;
}
StrCpy(_output,argv[1]);
printf("The Final String is::: \n[%s]\n",_output);
return 0;
}

int StrCpy(char *_output, const char *_input1)
{
int _cntr1 = 0;
while(*(_input1 + _cntr1) != NULL)
{
*(_output + _cntr1) = *(_input1 + _cntr1);
_cntr1++;
}
return 0;
}

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

What is the function of volatile in c language?

0 Answers  


main() { int i = -3,j=2,k=0,m; m= ++i || ++j && ++k; printf("%d%d%d",i,j,k,m); }

7 Answers   HCL,


Can we replace the struct function in tree syntax with a union?

0 Answers   Huawei,


What is modifier & how many types of modifiers available in c?

0 Answers  


What is a program flowchart and explain how does it help in writing a program?

0 Answers  






How do I create a directory? How do I remove a directory (and its contents)?

0 Answers  


triangle number finding program...

1 Answers   HCL,


What is your favorite subject?

1 Answers   Ericsson, Invendis, Tech Mahindra,


Just came across this question, felt worth sharing, so here it is I want you to make a C/C++ program that for any positive integer n will print all the positive integers from 1 up to it and then back again! Let's say n=5 I want the program to print: 1 2 3 4 5 4 3 2 1. Too easy you say? Okay then... You can ONLY USE: 1 for loop 1 printf/cout statement 2 integers( i and n) and as many operations you want. NO if statements, NO ternary operators, NO tables, NO pointers, NO functions!

1 Answers  


How can I implement opaque (abstract) data types in C? What's the difference between these two declarations? struct x1 { ... }; typedef struct { ... } x2;

2 Answers  


write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101)

1 Answers   Bosch, College School Exams Tests,


Explain data types & how many data types supported by c?

0 Answers  


Categories