code for copying two strings with out strcpy() function.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
#define MAX 3 main() { printf("MAX = %d ",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif }
When is an interface "good"?
what is c language?
How can I handle floating-point exceptions gracefully?
What are the main characteristics of c language describe the structure of ac program?
how to TOGGLE Nth bit of variable in a MACRO
How can I get random integers in a certain range?
Is it acceptable to declare/define a variable in a c header?
What is self-referential structure in c programming?
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"
What is time null in c?
What does s c mean on snapchat?