Reads a single word into a character array and then prints the word backward. - C Array

C examples for Array:Array Value

Introduction

Use strlen() to compute the index of the last character in the array.

Demo Code

#include <stdio.h>
#include <string.h>

int main(void){
  char word[30];/*  w w w.j a va  2 s.  c  om*/

  printf("Enter a string: ");
  scanf("%s", word);
  for (int i = strlen(word) - 1; i >= 0; i--){
    printf("%c", word[i]);
  }
  return 0;
}

Result


Related Tutorials