char *ch = "abcde";
char c[4];
how to copy 'ch' to 'c'?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Answer / supriya pandey
i think we used the string libruary function strcpy() to
copy it...
| Is This Answer Correct ? | 1 Yes | 4 No |
What is the disadvantage of using a macro?
Explain unexpected() function?
Can we use struct in c++?
What is searching?
What kind of problems can be solved by a namespace?
What is the average salary of a c++ programmer?
What are mutator methods in c++?
Is c++ the hardest programming language?
What is the difference between a type-specific template friend class and a general template friend class?
How can an improvement in the quality of software be done by try/catch/throw?
What sorting algorithm does c++ use?
Discuss the possibilities related to the termination of a program before entering the mainq method?