Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. /*
  2.  * 14:  
  3.  *
  4.  * Write a program that reads in a line of input and then prints the line in
  5.  * reverse order. You can store the input in an array of char; assume that the
  6.  * line is no longer than 255 characters. Recall that you can use scanf() with
  7.  * the %c specifier to read a character at a time from input and that the
  8.  * newline character (\n) is generated when you press the Enter key.
  9.  */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #define SIZE 256    //we need one more for \n
  13.  
  14. int main(void){
  15.     char arr[SIZE];
  16.  
  17.     printf("Provide a line of character(<= 255): \n");
  18.    
  19.     int i;
  20.     int notLineEnd = scanf("%c", &arr[0]);
  21.     while(notLineEnd){
  22.         i++;
  23.         notLineEnd = scanf("%c", &arr[i]);
  24.         printf("%d", notLineEnd);
  25.  
  26.     }
  27.  
  28.     int j;
  29.     for(j = 0; i < strlen(arr); j++){
  30.         printf("%c", arr[j]);
  31.     }
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement