Δημοσιεύτηκε: 17 Φεβ 2012, 23:14
- Κώδικας: Επιλογή όλων
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSLEN (80+1)
void Display_reverse(char *s);
int main()
{
char *s = NULL;
int maxlen;
char input[MAXSLEN]={'\0'};
printf(" Give the len : ");
fgets(input , MAXSLEN , stdin);
maxlen = atoi(input);
s= calloc( maxlen , sizeof(char));
printf(" Give a string : ");
fgets( s , maxlen , stdin);
if( s == NULL)
puts("Calloc failed");
Display_reverse(s);
printf("%s" , s);
free(s);
return 0;
}
//----------------------------------------------------------------------
void Display_reverse(char *s)
{
char *cp;
for(cp = s; *cp!='\0' && *cp!='\n'; cp++)
putchar(*cp);
puts("\n");
return;
}
Ειναι λιγο περιττή εδω η Display_reverse ή ειναι η ιδέα μου?