473,387 Members | 1,628 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,387 software developers and data experts.

code output

I know this is probably something silly, but I am missing something. I put the following into my compiler and I am not getting it. I know I need something to make this work, because everyone else is getting it. My project is to enter the following into the compiler and tell what the output would be (like 'abc').

char Ch='/';
while (Ch !='d')
{
putchar(Ch);
Ch = getchar();
}

Please help!
Nov 15 '07 #1
7 1450
weaknessforcats
9,208 Expert Mod 8TB
What I see is that Ch is a /

Then you drop to the loop where a / is not a d so you drop into the loop an display: /

Then you get a char, say a
and display: a

Then you get a char, say b
and display b.

Then you get a char, say c
and display c.

Then you get a char, say d
and exit the loop.

So you output is /aabbccd

Your letters are echoed when you enter them and then they are displayed. Except for the d which is newver displayed.

Now, then what is your question?
Nov 15 '07 #2
JosAH
11,448 Expert 8TB
I know this is probably something silly, but I am missing something. I put the following into my compiler and I am not getting it. I know I need something to make this work, because everyone else is getting it. My project is to enter the following into the compiler and tell what the output would be (like 'abc').

char Ch='/';
while (Ch !='d')
{
putchar(Ch);
Ch = getchar();
}

Please help!
If you fed that to your compiler verbatim it is never going to work. You have to put
those statements in a function, most likely int main() { /* your code */ return 0; }

kind regards,

Jos
Nov 15 '07 #3
If you fed that to your compiler verbatim it is never going to work. You have to put
those statements in a function, most likely int main() { /* your code */ return 0; }

kind regards,

Jos
So, I know this still might be silly, but I am still confusing how this is put into the compiler.

I would have to enter it as:

int main()
{
char Ch='/';
while (Ch !='d')
{
putchar(Ch);
Ch=getchar();
}

As you can see, I am missing something, and that is where I am stuck. My textbook does not really address this.

Thanks for any guidance.
Nov 15 '07 #4
I believe you'll need

return 0;

on the end
Nov 15 '07 #5
oler1s
671 Expert 512MB
And you need to #include <stdio.h> . Remember to include the header for whatever functions you want to use. putchar and getchar are not intrinsic to C.
Nov 15 '07 #6
Guys,

I am desperate, I have tried to input this and the other programs I am working on that are similar and I don't know why it isn't working. On this problem, I am supposed to input abcdefghi and my only possible solutions are a. abc b. d c. /abc or d. /efghi

2) Another one I can't get to work is what is supposed to happen when the following code is entered:

char Ch;
Ch='7';
printf("%d\n", Ch);

3) And still another I can't get to work, what would be the effect on entering this code:

char Ch;
while ((Ch=getchar())!=';')
putchar (Ch);

4) What would be the effect of the following:

char Ch;
while ((Ch=getchar()!='\n')
putchar(' ');

As I said, I am desperate to getting this done. If any of you are from Portland, I'll even take you out to eat.
Nov 30 '07 #7
oler1s
671 Expert 512MB
You're looking for an answer, not to learn. Unfortunately, that's not how programmer and technical forums work. We're interested in helping people learn, and when someone comes by focused on just getting an answer to walk away with, we don't bother.
Nov 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process,...
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
1
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
1
by: al jones | last post by:
I'll try again as I'm obvioulsy standing in the middle of the forest and not seeing the trees ... I didn't think I was to old to learn new trick, but this has just about convinced me otherwise. I...
1
by: GAOZH | last post by:
I wrote below code to do calculation. But it donesn't work for negative numbers like if input 4 + ( - 5 ), the program will crash. Any one can help me to modify the code to make it can calculate...
1
by: aboood | last post by:
Hi guys Could any one tell me what does that code do please? in pseudo-code #include <fstream.h> #include <iostream.h> bool differsByOneDigit ( int , int ); void outputResults ( ofstream & ,...
8
by: wastedhello | last post by:
ok. here are a list of things i cant fix. ive been trying for way to long now. 1. if more then 1000 values are told, will still continue with program. 2. if -max, min, average etc run, and 2...
25
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of...
1
by: gdarian216 | last post by:
okay I had a code that asked user to input a file name and instead i changed it to take the input from the command line. I now want to output results of some functions to an output file. I have...
10
by: len | last post by:
I have created the following program to read a text file which happens to be a cobol filed definition. The program then outputs to a file what is essentially a file which is a list definition...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.