Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to implement the function strrev() in C

2 Answers

0 votes
#include <stdio.h>
#include <string.h>

char* strrev(char* str) {
    char *p1, *p2;

    if (!str || !*str)
        return str;

    for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
        *p1 ^= *p2;
        *p2 ^= *p1;
        *p1 ^= *p2;
    }

    return str;
}

int main(void) {

    char str[16] = "c c++ java";
    
    strrev(str);

    puts(str);

    return 0;
}



/*
run:

avaj ++c c

*/

 



answered Jan 7, 2024 by avibootz
0 votes
#include <stdio.h>
#include <string.h>

char* strrev(char* str) {
    char *p1, *p2;

    if (!str || !*str)
        return str;

    for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
        char tmp;
        tmp = *p2;
        *p2 = *p1;
        *p1 = tmp;
    }

    return str;
}

int main(void) {

    char str[16] = "c c++ java";
    
    strrev(str);

    puts(str);

    return 0;
}



/*
run:

avaj ++c c

*/

 



answered Jan 7, 2024 by avibootz

Related questions

1 answer 256 views
256 views asked Mar 2, 2021 by avibootz
1 answer 187 views
1 answer 139 views
139 views asked Jun 10, 2025 by avibootz
1 answer 192 views
1 answer 202 views
1 answer 147 views
147 views asked Aug 2, 2024 by avibootz
1 answer 174 views
...