Created
June 30, 2012 11:27
-
-
Save marchrius/3023443 to your computer and use it in GitHub Desktop.
Reverse a word or a phrase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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