answersLogoWhite

0


Best Answer

As usual, you should check official documentation before you ask a question like this.

string.h

// Copies num characters from source into destination.

char* strncpy (char* destination, const char* source, size_t num);

// Copies characters from source into destination.

char* strcpy (char* destination, const char* source);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

#include <windows.h> #include <stdio.h> void main() { CHAR szTest[32] = {"The Quick Brown Fox"}; CHAR szCopy[32] = {0}; size_t thelen = strlen(szTest); int i = 0; for(;i<(int)thelen;i++) { szCopy[i] = szTest[i]; } }

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

char *strcpy(char *p1, const char *p2) char *pt = p1, while (*(p1++) = *(p2++)), return pt;

... or, at warning level 4 ...

char *strcpy(char *p1, const char *p2) char *pt = p1, while ((*(p1++) = *(p2++)) != '\0'), return pt;

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

/* copying srce to dest
*/

char *srce, *dest;
...
/* do whatever until copy required then:
*/
{
char *ptr = dest, *ptr2 = srce;
while (*ptr++ = *ptr2++);
}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

a c program to perform string manipulators

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

char* strcpy (const char* src, char* dst) {

char* temp = dst;

while ((*dst++ = *src++) != '\0);

return temp;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program to copy one string to another?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How did copy string one variable to another variable in body of the program in c?

/*Program to Copy one string to another using pointer.*/#include#includemain(){char a[80],b[80],*pa,*pb;int i=0;clrscr();printf("Given first string ");scanf("%s",a);pa=&a[0];pb=&b[0];while(*pa!='\0'){*pb=*pa;pa++;pb++;}*pb='\0';printf("\nCopied string is");puts(b);}


Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


How do you copy a string from one method into another string in another method in java?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.

Related questions

How did copy string one variable to another variable in body of the program in c?

/*Program to Copy one string to another using pointer.*/#include#includemain(){char a[80],b[80],*pa,*pb;int i=0;clrscr();printf("Given first string ");scanf("%s",a);pa=&a[0];pb=&b[0];while(*pa!='\0'){*pb=*pa;pa++;pb++;}*pb='\0';printf("\nCopied string is");puts(b);}


Can you copy pictures from one licensed commercial program to another in-house program to be used at multiple sites?

Not without permission. The EULA of the original program probably spells this out.


When was One String Leads to Another created?

One String Leads to Another was created in 1999.


Write a program to copy the value of one string variable to another variable?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


How do you copy an installed program from one hard drive to another hard drive?

i'm sorry that's not possible. you cant hover the installer program on to a hard disk but not a previously installed program.


Can you write a c program to copy one string to another without using library function?

#include&lt;stdio.h&gt; void main() { int str[20],str1[20],i,j=1; printf("enter the string"); gets(str); for(i=1;str[i]!='\0';i++) { str1[j]=str[i]; j++; } if(str1[j]!='\0') { puts(str1); } getch(); }


How do you copy a string from one method into another string in another method in java?

You can have two String variables (note that String variables are object references) refer to the same String object like so: String str1 = "Hello"; String str2 = str1; Now the str1 and str2 are references for the same String object containing the word "Hello". If you actually want a new String object with a copy of the contents of the original String, you use the String constructor that takes a String argument, like so: String str3 = new String(str1); Now str1 and str3 refer to SEPARATE String objects that happen to contain the same sequence of characters (the word "Hello"). Since Strings objects in Java are immutable, they can be shared without worrying about the contents used by one variable being upset by the use through another variable as might happen with char[] arrays in C or C++ so the first method is probably sufficient for most cases.


Which function joins one string with another to produce single string that contains both?

strcat()


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How do you copy a dos file from one location to another?

"copy &lt;source&gt; &lt;destination&gt;"


Write a program to copy the contents of one file to another?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main(int x,char *a[]) { FILE *fp1,*fp2; fp1=fopen("input.txt","r"); fp2=fopen("output.txt","w"); while(!(feof(fp1))) { fputc(fgetc(fp1),fp2); } fclose(fp1); fclose(fp2); return 0; }