A function that reverses a string of characters My problem is in writing a function reverse(s) that reverses the character string s, a line at a time. My code here works, I write the line and it reverses the line. Is it a good solution?

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#define MAX 1000

void  reverse(char cad[] ,char cadenita[],int i);

int main() {
    int a ,i ;
    char cad[MAX] = {0,0};
    char cadenita[MAX];
    i= 0;
      while ((a = getchar()) != EOF) {
          if (a != '\n') {
             cad[i] = a;
              ++i;
          }
          else  {                  
              cad[i] = '\0' ;              
             reverse(cad , cadenita, i);             
              printf("%s\n",cadenita);           
              i = 0;
          }                  
   }     
    return (EXIT_SUCCESS);
}

void  reverse(char s[] ,char svol[], int i) {
    int a =0 ;
    // i is the amount characters in s

    while ((svol[a] = s[i-1]) != '\0' ){
        ++a;
        --i;       
    }   

} 


Also in this part of code while ((svol[a] = s[i-1]) != '\0' ){ . 
If I change to  ((svol[a] = s[i-1]) != '\n' ) it still works and gives the same result, but why? I think there is an issue. Can you explain? Also, where does it break?
Naming

The mix of Spanish and English is disconcerting: cad vs. s.  The use of cadenita for the reversed string also seems odd, since the reversed string is the same length as the original.  svol is even weirder, as s appears to be short for "string" (English) and vol, I'm guessing, is short for "volvió" (Spanish).  Keep in mind that the function's name, reverse, is English.  (Personally, I recommend using English everywhere.)

i is conventionally used as an iteration dummy variable rather than as a length parameter.  If you mean length, then call the parameter len or length.  Using size_t instead of int would also be a good hint to its purpose.

Function declaration

Does reverse() operate on NUL-terminated strings or on a byte array of a specified length?  You should make up your mind, since bugs tend to occur when the two conventions get mixed up.  If the function takes a length, then it shouldn't look for '\0'.  Alternatively, if looks for '\0', then it shouldn't accept a length parameter.

Since allocating memory is an annoyance in C, I would consider it idiomatic for the reverse() function to operate on the string in place rather than making a copy.  If the caller wants to keep the original string intact, then make it the caller's responsibility to duplicate the string first.

It is conventional to place main() last, so that you don't need to make forward declarations of the functions that it calls.

Input

I don't recommend reading a character at a time using getchar().  Character-at-a-time I/O is less efficient.  More importantly, using a more appropriate function to read an entire line can simplify your code.  Using getline(), for example, makes your intentions clearer, and it avoids the possibility of a buffer overflow.

#include &lt;stdio.h&gt;

char *reverse(char *s, size_t len) {
    for (int i = 0, j = len - 1; i &lt; j; i++, j--) {
        char swap = s[i];
        s[i] = s[j];
        s[j] = swap;
    }
    return s;
}

int main() {
    char *line = NULL;
    size_t linecap = 0;
    ssize_t linelen;
    while ((linelen = getline(&amp;line, &amp;linecap, stdin)) &gt; 0) {
        if (line[linelen - 1] == '\n') {
            line[--linelen] = '\0';
        }
        puts(reverse(line, linelen));
    }
}