Input line reverser (2)

A

Albert

Sorry to all in previous topic - I decided to start a fresh one about
the same thing because the old one was getting a bit 'busy'.

I've 'desk-checked' and I still can't figure out why if I enter 'he' it

outputs 'ee'.
Could you give me another hint?


I've updated the program:


#include <stdio.h>
#define MAXINPUT 256


void reverse(char[], int);


main()
{
int c;
int number = 0;
char s[MAXINPUT];
int i;


for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n') && (c!=EOF);
i++) {
s = c;
++number;
}
reverse(s, number);


for (i=0; i<=number-1; i++)
putchar(s);
return 0;



}


void reverse(char s[], int num_elements)
{
int i, j;

for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s = s[j];

}
 
S

slebetman

Albert said:
Sorry to all in previous topic - I decided to start a fresh one about
the same thing because the old one was getting a bit 'busy'.

I've 'desk-checked' and I still can't figure out why if I enter 'he' it

outputs 'ee'.
Could you give me another hint?


I've updated the program:


#include <stdio.h>
#define MAXINPUT 256


void reverse(char[], int);


main()
{
int c;
int number = 0;
char s[MAXINPUT];
int i;


for (i=0; (i<MAXINPUT-1) && ((c = getchar()) != '\n') && (c!=EOF);
i++) {
s = c;
++number;
}
reverse(s, number);


for (i=0; i<=number-1; i++)
putchar(s);
return 0;



}


void reverse(char s[], int num_elements)
{
int i, j;

for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s = s[j];

}


You haven't desk-checked. Check out my response to your earlier post:

http://groups.google.com/group/comp...c87c4c/1ff90333e991b2a7?#doc_c96bbad7c240b139
 
R

Richard Heathfield

Albert said:
Sorry to all in previous topic - I decided to start a fresh one about
the same thing because the old one was getting a bit 'busy'.

I've 'desk-checked' and I still can't figure out why if I enter 'he' it

outputs 'ee'.
Could you give me another hint?

I gave you three, in the original thread. You can read them there. If you
think the other thread was 'busy', you can't have been on Usenet for more
than about a day. Have a bit of patience, and get a robust newsreader.
 
M

Mark McIntyre

Sorry to all in previous topic - I decided to start a fresh one about
the same thing because the old one was getting a bit 'busy'.

If you keep starting new threads because you don't like the responses
in the last one, you're likely to get killfiled quite quickly.
Mark McIntyre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top