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

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

1 Answers  


When is an interface "good"?

1 Answers  


what is c language?

2 Answers  


How can I handle floating-point exceptions gracefully?

0 Answers  


What are the main characteristics of c language describe the structure of ac program?

0 Answers  


how to TOGGLE Nth bit of variable in a MACRO

1 Answers   NDS,


How can I get random integers in a certain range?

0 Answers  


Is it acceptable to declare/define a variable in a c header?

0 Answers  


What is self-referential structure in c programming?

0 Answers  


Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"

0 Answers  


What is time null in c?

0 Answers  


What does s c mean on snapchat?

0 Answers  


Categories