M
Mark
Hello
as an exercise routine, here is a short C function, reversing a source
string and writing the result in the destination buffer. Would be glad to
hear some critics and advices on improvements. Thanks in advance.
#include <stdio.h>
#include <string.h>
void reverse(char *d, const char *s)
{
int i = 0;
size_t len = strlen(s) - 1;
do {
d[i++] = s[len--];
} while (len != 0);
d = '\0';
}
int main(void)
{
char s[100];
reverse(s, "This is a fairy long string to be reversed soon.");
printf("%s\n", s);
return 0;
}
as an exercise routine, here is a short C function, reversing a source
string and writing the result in the destination buffer. Would be glad to
hear some critics and advices on improvements. Thanks in advance.
#include <stdio.h>
#include <string.h>
void reverse(char *d, const char *s)
{
int i = 0;
size_t len = strlen(s) - 1;
do {
d[i++] = s[len--];
} while (len != 0);
d = '\0';
}
int main(void)
{
char s[100];
reverse(s, "This is a fairy long string to be reversed soon.");
printf("%s\n", s);
return 0;
}