/* program to print lines backwards */
#include <stdio.h>
# define BUFFERSIZE 80
main()
{
char buffer[BUFFERSIZE];
char *bp; /* a pointer to a character */
int k, j; /* loop induction variables */
bp = buffer;
while ( fgets(buffer, BUFFERSIZE, stdin) != NULL ) {
/* buffer has one line of input */
printf("the line backwards:\n");
/* find the end of the line */
k = 0;
while ( *(buffer+k) != '\0' ) k++;
k--;
if ( (k >= 0) && (*(buffer+k) == '\n') ) k--;
/* print relevant characters in reverse order */
for ( j = k; j >= 0; j-- ) {
printf("%c", *(buffer + j));
}
printf("\n");
}
return(0);
}
The blog provides study material for Computer Science(CS) aspirants. Mostly says "material nahi milta, padhun kahan se.", I think If you can not find content on the Internet, then you are not a CS student. Dedicated to (Prof. Rakesh Kumar, DCSA, K.U.Kurukshetra, HARYANA, INDIA)- "Ek teacher ka bahut jyada padhna, bahut jyada jaroori hota hai."
Sunday, 13 October 2013
program to print a string backwards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment