There is almost nothing to explain if you know C Language. Here is the program:
#include
void copyString(const char *src, char *dest);
int main() {
char str1[100];
char str2[100];
printf("Enter the string: ");
gets(str1);
copyString(str1, str2);
printf("Copied string: %s\n", str2);
return 0;
}
void copyString(const char *src, char *dest) {
while (*dest++ = *src++);
}
As you can see actually copying is done in just one line of code. While loop stops after it reaches zero value and all strings in C language are null-terminated strings (ending with 0x00 byte at the end of string, which is zero).
Testing:
Enter the string: Hello world, we have copy function for string!
Copied string: Hello world, we have copy function for string! Note: You should not be using gets() in real application, because it is not possible to limit number of the characters to be read thus allowing to overflow buffer. You might get a warning in line with our while loop if you are compiling with -Wall option in GCC, what does -Wall is that it checks for questionable places. This place for compiler is questionable because we have assignment operation inside while loop expression. Most of the times this is common mistake in programming, but not in this situation. Compiler just give a notice for developer that we should be careful.
A string in C is a character array, so you could simply copy one character at a time using a loop. (Be careful, things like this are the cause of many security holes using buffer overflows)
void myhomework (char *to, const char *from)
{ while (*to++ = *from++); }
there is no such method using string copy
If you don't need to preserve the first string you could just iterate over the second string and copy each character onto the end of the first string, then return that
what is string
/*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);}
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[10],str2[10]; printf("Enter string.\n"); gets(str2); strcpy(str2,str1); printf("Copied string is %s",str1); getch(); }
there is no such method using string copy
If you don't need to preserve the first string you could just iterate over the second string and copy each character onto the end of the first string, then return that
use strcat, strncpy, stpcpy, sprintf, strlen+memcpy, etc
1.take while loop in which u continue up to null in array of string. 2.once u get null pointer then take a new array of same length. 3.when u get null there ll save position no in variable i. 4.take while loop i to 0; 5.and j=0 for new array. 6.in above loop copy old array to new array in each cycle of loop. 7.j++; 8.u ll get reverse of string.
you can have an iPod without an iTunes, using Copy trans suite.it's a free program.
You can use so called concatenation of strings:{...string str1 = "something here";string str2 = " and something here";string newStr = str1 + str2;...}
what is string
#include<iostream> #include<string> int main() { // the two strings to concatenate std::string str1 = "Hello "; std::string str2 = "world!"; // allocate memory to the concatenated string with null-terminator char* str3 = new char[str1.size() + str2.size() + 1]; // initialise a moving pointer char* p = str3; // copy from the first string memcpy( p, str1.c_str(), str1.size() ); // advance the pointer p += str1.size(); // copy from the second string memcpy( p, str2.c_str(), str2.size() ); // advance the pointer p += str2.size(); // set the null-terminator *p = 0; // print concatenated string std::cout << str3 << std::endl; // tidy up delete [] str3, str3 = NULL; }
Output visual data - they allow us to avoid using hard copy only (printers) as output.
If you're using the std::string, why don't you just create another string instance like this: std::string hello = "hello"; std::string hello1; hello1 = hello; This will have copied the contents of the variable hello into hello1; char *psz1 = "This is a test."; char *psz2 = "..............."; // note - must be same or greater number of characters as psz1 char *p1 = psz1; char *p2 = psz2; while ((*p2++ = *p1++) != '\0'); // copy p1 to p2 Note: This is a trivial example, and might not work on most modern compilers that treat string literals as const or that place them into read-only memory. To solve this you need to replace the second line with ... char *psz2 = new char[16]; ... and then test to make sure that psz1 != NULL.
#include<stdio.h> 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(); }
The only way to copy Xbox 360 games and play them on your 360 without using a modchip is to use the guide at: http://copyxbox360games.blogspot.com