ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
code for copying two strings  with out strcpy() function.
 Question Submitted By :: Pinky
I also faced this Question!!     Rank Answer Posted By  
 
  Re: code for copying two strings with out strcpy() function.
Answer
# 1
#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 ?    1 Yes 0 No
Ali
 
  Re: code for copying two strings with out strcpy() function.
Answer
# 2
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 ?    1 Yes 2 No
Reachhary
 
 
 
  Re: code for copying two strings with out strcpy() function.
Answer
# 3
#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 ?    3 Yes 0 No
Vignesh1988i
 
  Re: code for copying two strings with out strcpy() function.
Answer
# 4
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 0 No
Ankitecian
[TCS]
 
  Re: code for copying two strings with out strcpy() function.
Answer
# 5
#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 ?    0 Yes 0 No
Suman_kotte
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE? Wipro1
Program to display given 3 integers in ascending order N-Tech1
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means.... TCS1
Write a program to compare two strings without using the strcmp() function Accenture14
how to find the kth smallest element in the given list of array elemnts. Silicon5
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); } ME3
program to find which character is occured more times in a string and how many times it has occured? for example in the sentence "i love india" the output should be i & 3.  3
Whats wrong with the following function char *string() { char *text[20]; strcpy(text,"Hello world"); return text; } Qualcomm3
palindrome for strings and numbers----Can anybody do the prog? TCS6
What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture3
write a program to find out number of on bits in a number? Huawei12
Design a program using an array that lists even numbers and odd numbers separately from the 12 numbers supplied by a user.  7
pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent4
how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--); RMSI16
what is a c-language.what is do. HCL3
when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none HCL4
c program to add and delete an element from circular queue using array  1
What is the purpose of Scanf Print, getchar, putchar, function?  2
Print all numbers which has a certain digit in a certain position eg: number=45687 1 number=4 2 number=5 etc  2
#define d 10+10 main() { printf("%d",d*d); }  3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com