File: string_reverse.c

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (24 lines) | stat: -rw-r--r-- 363 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string.h>
#include <stdlib.h>

const char *
string_reverse(const char *input)
{
  static char *output = NULL;
  int i, len;

  if(output != NULL)
    free(output);

  if(input == NULL)
    return NULL;

  len = strlen(input);
  output = malloc(len+1);

  for(i=0; input[i]; i++)
    output[len-i-1] = input[i];
  output[len] = '\0';

  return output;
}