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 difference between the indirection operator and the address of oper-ator?
What does the following do: for(;;) ; a) Illegal b) Loops forever c) Ignored by compiler...not illegal
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
What are special characters c++?
What are class and object in C++?
write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num
How to allocate memory dynamically for a reference?
Can I learn c++ without knowing c?
What is the arrow operator in c++?
Will a catch statement catch a derived exception if it is looking for the base class?
In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest.
int main() { int i ,a[i]; i = 0; a[i] = 10; cout<< a[i] << endl; return 0; } What will be output of this program?