#include "stdio.h"
#include "conio.h" // getch ()
#include "windows.h" // strlen()
int get_strlen(char * string);
Code:
int main()
{
char input[80] = { NULL }, // { NULL } sets all the subscript to NULL
ch;
int idx = 0;
printf("\n Input : ");
gets(input);
printf("\n input = [ %s ] ",input);
// strlen() returns the number of chars in input
idx = strlen(input);
// idx = get_strlen(input);
// right here is where it's done - swap first and last char
ch = input[--idx];
input[idx] = input[0];
input[0] = ch;
printf("\n input = [ %s ] ",input);
printf("\n ------\n\n");
getch(); // press any key to continue
return 0;
}
// Use this is you don't have strlen() or windows.h
int get_strlen(char * str)
{
int nbr = 0;
// \0 = NULL
while(str[nbr] != '\0')
nbr++;
return nbr;
}
I posted another thing similiar to this one on the board.
* Note : written in C - i hope you can get ideas from it.