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 |
typedef struct { int i:8; char c:9; float f:20; }st_temp; int getdata(st_temp *stptr) { stptr->i = 99; return stptr->i; } main() { st_temp local; int i; local.c = 'v'; local.i = 9; local.f = 23.65; printf(" %d %c %f",local.i,local.c,local.f); i = getdata(&local); printf("\n %d",i); getch(); } why there there is an error during compiling the above program?
what r callback function?
different between overloading and overriding
what is the different between data structure and data type?
Describe the header file and its usage in c programming?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
How to write the code of the program to swap two numbers with in one statement?
Why clrscr is used in c?
What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value.
What is string function c?
Reverse a string word by word??
What are the preprocessor categories?