I have to make a C program read ordinary text (a sequence of lines) from the program's standard input, and print it with each line reversed from left to right. It has to be no longer than 80 symbols and it should read until it gets an EOF. Im stumped now...here is what i have so far...

#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 80

int getline(char *, int);

void main() {
char a[MAXLEN];
int i;
int temp;
int n;

getline(a, MAXLEN);

for (i=0; i<n/2; i++) {
temp = a;
a     = a[n-i-1];
a[n-i-1] = temp;
printf("%s", a);



/* getline: read a line into s,  return length */

int getline(char *s, int lim)
int c, i;

for (i = 0; i < lim-1 &&(c=getchar())!= EOF && c != '\n'; ++i)
s = c;
if (c == '\n') {
s = c;
s = '\0';
return i;

Recommended Answers

All 2 Replies

loops can be traversed in either direction. Decrease your counter from the length of a string to 0 while printing.

That's all the hint you should need.

yeah right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.