473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Input line reverser (2)

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

}

Dec 30 '05 #1
3 1108
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

Dec 30 '05 #2
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)
Dec 30 '05 #3
On 29 Dec 2005 20:57:43 -0800, in comp.lang.c , "Albert"
<al*****************@gmail.com> 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 =----
Dec 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Trevor Fairchild | last post by:
Hello, all. I am writing a program that parses an html report (generated by another program). I use the Open "C:\...." for Input As myValue method to open the html, and read through it...
5
by: Gregg | last post by:
Hello all, I have been banging my head over a problem that I am having reading a comma seperated file (CSV) that can contain from 1 to 10,000 records. My code snipit is as follows: **Start...
2
by: SophistiCat | last post by:
Hi, I am working on a computational program that has to read a number of parameters (~50) from an input file. The program contains a single class hierarchy with about a dozen member-classes or...
4
by: R Bolling | last post by:
I have a text file from a text document that has very long rows (two or three paragraphs from a text document for each row). Importing to text cuts it off at 255 characters, and importing to a...
4
by: santa19992000 | last post by:
can I use scanf to get input (some times user enters input sometimes not, just hit keyboard)?. It displays to enter IP address, if user wants to change, then he enters, otherwise he hits keyboard,...
39
by: Albert | last post by:
This not-yet-working C program's aim is to output each input line reversed (so if the user enters 'hello', the program will output 'olleh' - and please assume this stdout and stdin!!!). Why the...
17
by: Martin Jørgensen | last post by:
Hi, Since I'm a newbie I have some small but quick (probably) stupid questions also :-) This is my "get_double" function which takes a default argument also of type double. The function...
8
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when...
3
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
2
by: sixtyfootersdude | last post by:
Good Morning! I am just starting to learn perl and I am somewhat mistifide about when I should do: print("@input"); and when I should do: print(@input)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.