Skip to content

Instantly share code, notes, and snippets.

@marchrius

marchrius/reverse.c

Created Jun 30, 2012
Embed
What would you like to do?
Reverse a word or a phrase
//
// reverse.c
//
//
// Created by Matteo Gaggiano on 23/06/12.
// Copyright (c) 2012 Marchrius. All rights reserved.
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char *line = (char*)malloc(sizeof(char*)); //definisco 1 variabile di tipo puntatore a char
int i, count = 0, len = 0;
char t;
printf("Inserisci la frase. Per terminare premi INVIO\n");
fgets(line, 1024, stdin);
len = strlen(line);
char line2[len];
line[len-1] = '\0';
len = strlen(line);
for (i = len-1; i>=0; i--) {
line2[i] = line[count++];
}
printf("Frase>> %s\nReverse>> %s\n", line, line2);
free(line);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment