Ad
Code
Diff
  • #include<stdbool.h>
    
    const char *bool_to_word (int value)
    {
      return (value)?"Yes":"No";
    }
    • #include<stdbool.h>
    • const char *bool_to_word (int value)
    • {
    • if (value == 0)
    • return "No";
    • else if (value!=0)
    • return "Yes";
    • return (value)?"Yes":"No";
    • }
Code
Diff
  • #include <stdlib.h>
    #include <string.h>
    
    char *reverse_string(const char *word) {
        if (!word) return NULL;
      
        int len = strlen(word);
        char *res = malloc(len + 1);
    
        for (int i = len ; i >= 0 ; res[i] = word[len - (--i) - 1]);
    
        res[strlen(word)] = '\0';
        return res;
    }
    • #include <stdlib.h>
    • #include <string.h>
    • char *reverse_string(const char *word) {
    • if (!word) return NULL;
    • size_t len = strlen(word);
    • int len = strlen(word);
    • char *res = malloc(len + 1);
    • if (!res) return NULL;
    • for (size_t i = 0; i < len; i++)
    • res[i] = word[len - i - 1];
    • for (int i = len ; i >= 0 ; res[i] = word[len - (--i) - 1]);
    • res[len] = '\0';
    • res[strlen(word)] = '\0';
    • return res;
Code
Diff
  • #include <stdlib.h>
    #include <string.h>
    
    char *reverse_string(const char *word)
    {
        if (!word)
            return NULL;
        
        char *res = malloc(strlen(word) + 1);
        for(int i = strlen(word) ; i>=0 ; res[i] = word[strlen(word) - (--i) - 1]);
        
        res[strlen(word)] = '\0';
        return res;
    }
    
    
    • #include <stdlib.h>
    • #include <string.h>
    • char *reverse_string(const char *word)
    • {
    • if (!word)
    • return NULL;
    • char *res = malloc(strlen(word) + 1);
    • int i = strlen(word);
    • while (res[i] = word[strlen(word) - (--i) - 1])
    • ;
    • for(int i = strlen(word) ; i>=0 ; res[i] = word[strlen(word) - (--i) - 1]);
    • res[strlen(word)] = '\0';
    • return res;
    • }
Code
Diff
  • #include <stdlib.h>
    #include <string.h>
    
    char *reverse_string(const char *word)
    {
        if (!word)
            return NULL;
    
        char *res = malloc(strlen(word) + 1);
        int i = strlen(word);
        while (res[i] = word[strlen(word) - (--i) - 1])
            ;
        res[strlen(word)] = '\0';
        return res;
    }
    
    • #include <stdlib.h>
    • #include <string.h>
    • char *reverse_string(const char *word) {
    • if (!word) return NULL;
    • char *reverse_string(const char *word)
    • {
    • if (!word)
    • return NULL;
    • size_t len = strlen(word);
    • char *res = malloc(len + 1);
    • if (!res) return NULL;
    • for (size_t i = 0; i < len; i++)
    • res[i] = word[len - i - 1];
    • res[len] = '\0';
    • char *res = malloc(strlen(word) + 1);
    • int i = strlen(word);
    • while (res[i] = word[strlen(word) - (--i) - 1])
    • ;
    • res[strlen(word)] = '\0';
    • return res;
    • }