473,614 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how does programme truly work when running the loop to read and output chars

1 New Member
(scroll down to see the codes)

I am writing a programme to read chars and output the new chars with continuous spaces being eliminated until one( say 'tes t' gonna to be 'tes t'

And then i found that the programme can't be stopped when i gave the former input on GDB(a online compiler)

My question is that what exactly happen after i press the key 'Enter', Does that key create a '\n' at the end of the input and gives the programme a command to start to run?

it is confusing to me because it's different to the function 'input()' in python, which have a timing to input. i thought the chars should be input firstly but why the programme keep asking input after calculating?
And how can i stop the following code to tell the programme my input ends?( namely, to make my last char == EOF )

really thankful if someone can answer because i know it could be a commonly basic question to most of programmers.


#include <stdio.h>

int main()
{
int c;
int button = 0;
while((c=getcha r())!= EOF){
if (c==' '&&button == 1){
continue;
}
putchar(c);
if (c ==' '){
button = 1;
}
else{
button = 0;
}



}

return 0;
}
Apr 10 '20 #1
1 1249
dev7060
644 Recognized Expert Contributor
EOF character may not be recognized in the console unless followed up with the enter key. It can be sent to the program with Ctrl-D (Unix) and Ctrl-Z (Microsoft).
Apr 10 '20 #2

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

Similar topics

7
7815
by: lawrence | last post by:
Suppose I create dynamic web pages with 3 functions (which call other functions to make everything happen, but these 3 you might think of as being the top layer): registerSessions(); sendHtmlToBrowsers(); incrementPageViews(); Is there any chance that incrementPageViews() will be executed? Or, to
4
2790
by: esoroka | last post by:
Hello, Trying to run a script what start ASP button: document.Form1.all.click(); It is work one time only. Next script ignore it. Where can be problem??? A full script is as follows:
0
1061
by: Peter Row | last post by:
Hi, I have written a DLL that implements IHttpHandler methods, i.e GetHandler, ProcessRequest etc... I also automatically login visitors to the site as an appropriate guest (based on browser language). To do the auto login I used FormsAuthentication with my Web.Config file specifying my guestlogin ASPX page as the page to use.
4
1926
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I haven't placed error handling code). When I run my app from the IDE, the unhandled errors are caught by the error handling code in my Sub Main routine and the error details are logged to a text file and optionally e-mailed to me for follow-up.
2
4897
by: Oenone | last post by:
I am developing an assembly that can be used either by a Windows Forms application or from within an ASP.NET web site. When running within the Forms app, I can break into the code while it is running and use edit-and-continue to modify the sourcecode and then immediately execute the modifications. When running within the web site, the source-code is all read-only when I break into it. The little padlock icon appears in the tab for each...
0
902
by: Alan Silver | last post by:
Hello, I have a web site that I developed before getting VWD Express. It was all written by hand and works fine. I have installed VWDE and thought I would try opening this site in it. The site uses forms authentication, and this is giving me problems. Part of the code checks the value of User.Identity.Name, which when run normally (ie from a browser) contains the name of the logged-in user. When run in the VWDE IDE, this contains...
51
3912
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and output to be within one directory, and I want to be able to combine files from different directories into another directory of my choice). My program seems to work fine, but I'm wondering about this loop: for (int i = 0; i < numFiles; i++)
5
8978
by: =?Utf-8?B?cnZhbmdlbGRyb3A=?= | last post by:
Hello, I have a problem with our OnlineBackupService.exe. This is a Windows Service which is built in .Net 1.1 and basically grabs files from the file system and will try to upload them using WebServices. The service is installed by default using LocalSystem account. The exact problem is that sometimes this service is not allowed to resolve the target webservice. This results in the following exception:
3
293
by: xmail123 | last post by:
Why does this code work? I am new to C# and have been studying this piece of code. It loops through an Adjacency Matrix table to populate a tree view. I have two questions about why this code works. 1. initTreeView(TreeNode N) creates a new "temp" table to hold the children for each node. Each time the table is created it has the same name "temp". Why doesn't the table just get over written each time? 2. In the foreach (DataRow r3...
5
2779
by: chen shen | last post by:
Hi, I am trying to write to an output file. but "\n" does not do its job. Here's part of my perl code: open(OUT, ">dollars.txt") || die("could not write to a file!"); $array = @array; print OUT "There are $array values in the file: "; @cents;
0
8179
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8124
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5538
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4049
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1712
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1421
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.