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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the basic structure of a c++ program?

707


Why is c++ is better than c?

615


Why are pointers used?

653


What are the basic data types used in c++?

657


Which header file allows file i/o with streams a) fileio.h b) iostream.h c) fstream.h

759






Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.

697


What is the meaning of string in c++?

661


What is a pointer with example?

754


Which is the best c++ compiler for beginners?

651


Why do you use the namespace feature?

745


What programming language should I learn first?

691


Why is main function important?

686


How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Why is it difficult to store linked list in an array?how can you find the nodes with repetetive data in a linked list?

846


What is #include ctype h in c++?

763


Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement

722