Strings Manipulation
String representation
char word[7] = {"hellow"}; β always use double quotes and char type.
or
char word[7] = "hellow"; β can remove brackets.
or
char word[] = "hellow"; β this one is better.
Reversing a string
#include <stdio.h>
#include <string.h>
void reverse(char*, int, int);
int main()
{
char a[100];
gets(a);
reverse(a, 0, strlen(a)-1);
printf("%s\n", a);
return 0;
}
void reverse(char *x, int begin, int end)
{
char c;
if (begin >= end)
return;
c = *(x+begin);
*(x+begin) = *(x+end);
*(x+end) = c;
reverse(x, ++begin, --end);
}Analyzing strings
Example:
Finding mixed character strings (without string.h)
Summary
Last updated