How do you use the replace function to change a string.
How do you use the replace function to change a string.
Thanks for the correction. My question relates to writing a function that copies the contents of a string and then replaces it in reverse order. I am not fully aware of all the functions in C, so based on what I was able to find out, I thought there might be one.
Here is my code:
Any help would be appreciated!
#include <stdio.h>
#include <string.h>
void strcopy(char string1[], char string2[])
{
int i =0;
int length;
while ( string2[i] !='\0')
{
string1[i] = string2[i];
++i
}
string1[i] = '\o'
length = strlen( string1 );
while (string1[i] !='\o')
{
string2[i] = string1[length]
++i
--length
}
while (string2[length] !='\o')
return,
>My question relates to writing a function that copies the
>contents of a string and then replaces it in reverse order.
So you want to copy a string, reverse it, and then replace the original string with the reversed copy? That's too much work for a simple operation, this should have the same result in a more efficient manner:
-PreludeCode:void reverse ( char *s ) { int t, i, j; size_t len = strlen ( s ) - 1; for ( i = 0, j = len; i < j; i++, j-- ) t = s[i], s[i] = s[j], s[j] = t; }
My best code is written with the delete key.