Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


char *ch = "abcde";
char c[4];
how to copy 'ch' to 'c'?

Answers were Sorted based on User's Feedback



char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?..

Answer / parth ujenia

main()
{
char *ch="abcd";
char c[4];

for(int i=0;i<4;i++)
{
c[i]=*ch; //assign value to char c[i].
*ch++; //switch to next address of ch!
}

for(i=0; i<4 ;i++)
{
printf("%c - ",c[i]); //output will: a - b - c - d -
}

getch();

}

Is This Answer Correct ?    18 Yes 7 No

char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?..

Answer / gopi

main()
{
char *ch="abcd";
char c[4];

for(int i=0;i<4;i++)
{
c[i]=*ch;
ch++;
}


printf("%s",c);

getch();

}

Is This Answer Correct ?    12 Yes 2 No

char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?..

Answer / wade stone

#include <stdio.h>
#include <string.h>

using namespace std;

int main( )
{
char *ch = "abcde";
char c[4];

memcpy( c, ch, sizeof( c ) );

return 0;
}

Is This Answer Correct ?    2 Yes 1 No

char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?..

Answer / supriya pandey

i think we used the string libruary function strcpy() to
copy it...

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C++ General Interview Questions

When volatile can be used?

3 Answers   Symphony,


What is the difference between map and hashmap in c++?

0 Answers  


What does it mean to declare a destructor as static?

0 Answers  


WHAT IS THE ABREVATION OF FORTRAN?

4 Answers  


What are enumerations?

0 Answers  


Write my own zero-argument manipulator that should work same as hex?

0 Answers  


What is increment operator in c++?

0 Answers  


Brief explaination about #include<iostream.h>, cin and cout

3 Answers  


what is the diff b/n c and c++ a. dynamic scoping b. nested switching c. declaration of variables in any code block d. separation of compilation and linking

2 Answers   Hughes,


What is c++ course?

0 Answers  


Are c and c++ different?

0 Answers  


What do you mean by a template?

0 Answers  


Categories