Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Input line reverser (2)

Reply
Thread Tools

Input line reverser (2)

 
 
Albert
Guest
Posts: n/a
 
      12-30-2005
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[i] = c;
++number;
}
reverse(s, number);


for (i=0; i<=number-1; i++)
putchar(s[i]);
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[i] = s[j];

}

 
Reply With Quote
 
 
 
 
slebetman@yahoo.com
Guest
Posts: n/a
 
      12-30-2005
Albert wrote:
> 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[i] = c;
> ++number;
> }
> reverse(s, number);
>
>
> for (i=0; i<=number-1; i++)
> putchar(s[i]);
> 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[i] = s[j];
>
> }


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

http://groups.google.com/group/comp....6bbad7c240b139

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      12-30-2005
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      12-30-2005
On 29 Dec 2005 20:57:43 -0800, in comp.lang.c , "Albert"
<(E-Mail Removed)> wrote:

>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
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Line in connector input not working? disabled? input radio to computer. 8ball meme Computer Support 7 11-18-2010 10:39 PM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
Input-line reverser Albert C Programming 39 01-03-2006 11:19 PM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
EF lens reverser Paul Dalen Digital Photography 13 02-07-2004 07:24 PM



Advertisments