Contact: aviboots(AT)netvision.net.il
38,169 questions
49,785 answers
573 users
#include <stdio.h> #include <string.h> #define SIZE 30 void reverse(char s[]) { int i = 0, len = strlen(s) - 1; char rev[SIZE] = ""; while (len >= 0) { rev[i++] = s[len--]; } rev[i] = '\0'; strcpy(s, rev); } int main(void) { char s[SIZE] = "c c++ java"; reverse(s); puts(s); return 0; } /* run: avaj ++c c */
#include <stdio.h> #include <string.h> int main(int argc, char** argv) { char s[6] = "abcde", rev[6] = ""; strcpy(rev, s); _strrev(s); // windows MSVS printf("%s\n", rev); printf("%s\n", s); return 0; } /* run: abcde edcba */
#include <stdio.h> #include <string.h> #define SIZE 30 void reverse(char s[]) { int len = strlen(s); char tmp; for (int i = 0, j = len - 1 ; i < (len / 2); i++, j--) { tmp = s[j]; s[j] = s[i]; s[i] = tmp; } } int main(void) { char s[SIZE] = "c c++ java"; reverse(s); puts(s); return 0; } /* run: avaj ++c c */
#include <stdio.h> #include <string.h> int main() { char s[32] = "c c++ java"; _strrev(s); // windows MSVS printf("%s\n", s); return 0; } /* run: avaj ++c c */
#include <stdio.h> #include <string.h> #define SIZE 30 void reverse(char s[]) { char *start = s; char *end = start + strlen(s) - 1; char ch; while (end > start) { ch = *start; *start = *end; *end = ch; ++start; --end; } } int main(void) { char s[SIZE] = "c c++ java"; reverse(s); puts(s); return 0; } /* run: avaj ++c c */
#include <stdio.h> #include <string.h> char *strrev(char *s) { if (s && *s) { char *start = s, *end = s + strlen(s) - 1; while (start < end) { char t = *start; *start++ = *end; *end-- = t; } } return s; } int main() { char s[32] = "c c++ java"; strrev(s); printf("%s\n", s); return 0; } /* run: avaj ++c c */
#include <stdio.h> #include <string.h> #define LEN 32 int main(void) { char s[LEN] = "C Programming"; char* p; p = _strrev(s); printf("s = %s\n", s); printf("p = %s\n", p); printf("&s = %p\n", &s[0]); printf("&p = %p\n", p); return 0; } /* run: s = gnimmargorP C p = gnimmargorP C &s = 000000E58895F898 &p = 000000E58895F898 */