I'm trying to learn C from "The C Programming Language" (by K&R) and I
am about halfway through the first chapter.
I am using Miracle C as my text editor and compiler.
Up until this point everything was working fine, but now the book has
started into Line and Word counting programs. I am entering the
programs into the text editor exactly like they are in the book and
they are not working right at all. They compile fine and when I run
them they do no produce any output like they should be. Its strange.
I think it may be my compiler. Someone recommended my using DJPGG (i
think it was called) and I tried to install and run that program but
it seems way way way to complicated for me and I have noone who can
show me how to get it to run properly.
This is the line counting Prog:
#include <stdio.h>
main()
{
int c, nl;
nl = 0;
while ((c = getchar()) != EOF)
if (c == '\n')
++nl;
printf("%d\n", nl);
}
When I type things into the cmdprompt it will not give me any output (
i guess its called) Its almost like the printf cmd isnt there and it
is just taking in the data and not displaying anything. The word
counting program was basically the same and gave me the same result.
I enter something , hit enter and instead of printing anything on the
screen it pauses for a moment and then moves down to the next line.
Its frustrating. There is also wc program that comes straight from
UNIX in the book and when I enter the code exactly as it is in the
book into my compiler I get a weird error like it thinks the word OUT
is the number 0. Very strange....
I think the problem is my compiler. Can anyone recommend a good and
easy to use C compiler/text editor?? 22 2782
ext_u wrote: This is the line counting Prog: #include <stdio.h> main() { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d\n", nl); }
int main(void)
{
int nl;
char c;
nl = 0;
while( (c = getchar() ) != EOF)
{
if( c == '\n')
++nl;
}
printf("%d\n", nl);
return 0;
}
This type of program takes the input-file on standard input, so you
basically need to redirect a file to your program.
Example:
[hildrum:C-Programming] tor% wc -l linecount.c
18 linecount.c
[hildrum:C-Programming] tor% ./linecount < linecount.c
18
Tor
ext_u wrote: I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter.
I am using Miracle C as my text editor and compiler.
Up until this point everything was working fine, but now the book has started into Line and Word counting programs. I am entering the programs into the text editor exactly like they are in the book and they are not working right at all. They compile fine and when I run them they do no produce any output like they should be. Its strange. I think it may be my compiler. Someone recommended my using DJPGG (i think it was called) and I tried to install and run that program but it seems way way way to complicated for me and I have noone who can show me how to get it to run properly.
This is the line counting Prog: #include <stdio.h> main() { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d\n", nl); }
When I type things into the cmdprompt it will not give me any output ( i guess its called) Its almost like the printf cmd isnt there and it is just taking in the data and not displaying anything. The word counting program was basically the same and gave me the same result. I enter something , hit enter and instead of printing anything on the screen it pauses for a moment and then moves down to the next line. Its frustrating. There is also wc program that comes straight from UNIX in the book and when I enter the code exactly as it is in the book into my compiler I get a weird error like it thinks the word OUT is the number 0. Very strange....
I think the problem is my compiler. Can anyone recommend a good and easy to use C compiler/text editor??
No, the program is right. It's waiting for you to signal an EOF.
Control-Z should work for DOS. You might have to hit enter.
That program would work better by sending a file for it to read.
prog.exe < file.txt
Read about command output redirection, filters, and pipes somewhere.
I don't know of a good overview offhand, but it's some fundamental
knowledge.
On 17 Aug 2003 18:19:07 -0700, ex***********@h otmail.com (ext_u)
wrote: I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter.
I am using Miracle C as my text editor and compiler.
Up until this point everything was working fine, but now the book has started into Line and Word counting programs. I am entering the programs into the text editor exactly like they are in the book and they are not working right at all. They compile fine and when I run them they do no produce any output like they should be. Its strange. I think it may be my compiler. Someone recommended my using DJPGG (i think it was called) and I tried to install and run that program but it seems way way way to complicated for me and I have noone who can show me how to get it to run properly.
This is the line counting Prog: #include <stdio.h> main() { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d\n", nl); }
Your problem might be that you need a text file in the same directory
as your executable. Just type a few lines in a new text file or copy a
readme file from somewhere. Then on the command line enter:
"program_na me" < "text_file_name "
then your program will count the number of lines.
I believe this is your problem.
Bill
Bill Reed
Email = Subject: must include "clc"
ext_u wrote: I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter.
I am using Miracle C as my text editor and compiler.
Up until this point everything was working fine, but now the book has started into Line and Word counting programs. I am entering the programs into the text editor exactly like they are in the book and they are not working right at all. They compile fine and when I run them they do no produce any output like they should be. Its strange. I think it may be my compiler. Someone recommended my using DJPGG (i think it was called) and I tried to install and run that program but it seems way way way to complicated for me and I have noone who can show me how to get it to run properly.
This is the line counting Prog: #include <stdio.h> main() { int c, nl; nl = 0; while ((c = getchar()) != EOF) if (c == '\n') ++nl; printf("%d\n", nl); }
When I type things into the cmdprompt it will not give me any output ( i guess its called) Its almost like the printf cmd isnt there and it is just taking in the data and not displaying anything. The word counting program was basically the same and gave me the same result. I enter something , hit enter and instead of printing anything on the screen it pauses for a moment and then moves down to the next line. Its frustrating. There is also wc program that comes straight from UNIX in the book and when I enter the code exactly as it is in the book into my compiler I get a weird error like it thinks the word OUT is the number 0. Very strange....
I think the problem is my compiler. Can anyone recommend a good and easy to use C compiler/text editor??
I like the gcc compiler, which comes with the Linux
operating system. Here's how the program works with
gcc. (I've numbered the lines, so I can explain what
they mean.)
(1) gcc line_count.c -o line_count
(2) ./line_count
(3) The quick brown fox
(4) jumped over the
(5) gnarly net.
(6) Control-d
(7) 3
You type lines 1 and 2 into the computer.
Then you can type however many lines you want,
and then type Control-d, and the computer will
tell you how many lines you just entered into
the computer (minus the Control-d line).
ext_u wrote: I'm trying to learn C from "The C Programming Language" (by K&R) and I am about halfway through the first chapter.
I am using Miracle C as my text editor and compiler.
Up until this point everything was working fine, but now the book has started into Line and Word counting programs. I am entering the programs into the text editor exactly like they are in the book and they are not working right at all. They compile fine and when I run them they do no produce any output like they should be. Its strange. I think it may be my compiler. Someone recommended my using DJPGG (i think it was called) and I tried to install and run that program but it seems way way way to complicated for me and I have noone who can show me how to get it to run properly.
.... snip ... I think the problem is my compiler. Can anyone recommend a good and easy to use C compiler/text editor??
You didn't follow instructions on the DJGPP installation. It is
NOT a program, it is a system. Among other things you will get
gcc, the best C compiler available, and pretty well universally
used. Go through the sip-picker again, and be sure to get unzip32
with it, and to follow instructions.
--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
On Sun, 17 Aug 2003 18:19:07 -0700, ext_u wrote: while ((c = getchar()) != EOF)
When I type things into the cmdprompt it will not give me any output
This program reads until it gets to an EOF (end of file) character, so
unless you supply one it won't ever complete.
In linux ctrl-d (I think it was) makes and EOF character, don't know if
that works in windows but it may be worth a try. If it doesn't you'll have
to search the documentation to figure out how to input and EOF character
hth
NPV
In message <4aW%a.23577$KF 1.317975@amstwi st00>
Tor Hildrum <to*@hildrum.ne t> wrote: int main(void) { int nl; char c;
Doesn't getchar() return an int?
nl = 0;
while( (c = getchar() ) != EOF) { if( c == '\n') ++nl; }
printf("%d\n", nl);
return 0; }
Groeten,
Arjan
>> while ((c = getchar()) != EOF) When I type things into the cmdprompt it will not give me any output In linux ctrl-d (I think it was) makes and EOF character, don't know if
it was.
that works in windows but it may be worth a try. If it doesn't you'll have
sometimes. otherwise try ctrl-z. if that doesnot work too, I can't help either.
--
- Jan Engelhardt
"Nils Petter Vaskinn" <no@spam.for.me .invalid> writes: On Sun, 17 Aug 2003 18:19:07 -0700, ext_u wrote: while ((c = getchar()) != EOF)
When I type things into the cmdprompt it will not give me any output
This program reads until it gets to an EOF (end of file) character, so unless you supply one it won't ever complete.
Quibble: EOF is not a character, it's a macro that expands to a
negative integer constant expression ((-1) is typical). That's why
getchar() returns an int rather than a character type, so it can
return either a character value or EOF.
Just to add to the confusion, many systems use a specific input
character to signal an EOF condition for interactive input.
<OT>
Unix-like systems typically use control-D, but a program reading from
the keyboard will see an EOF condition, not a control-D character
('\004') -- though a mechanism exists for entering a control-D
character so that it will be seen by the reading program, *without*
triggering an EOF condition (control-V control-D). A control-D
character in a disk file will be read as a '\004' character, and will
*not* signal EOF. Other systems may behave differently; for example,
I think that a control-Z character ('\026') in an MS-DOS text file
actually does signal EOF.
</OT>
--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anand |
last post by:
Hi i am having trouble adding a recordset into the access database,
the code seems to be working fine it passs and parses through all
variables just fine without showing any errors and also when i access
the recordset it displays the results, what the real issue is that the
entry is not made into the database even though i use the Update
command and i have also tried the BeginTrans and CommitTrans nothign
seems to work and i am unable to...
|
by: ajackson |
last post by:
i am having some trouble installing SQl server Reporting Services.
well, in order to install the reporting services i have to install
Service
Pack 3a.
so through my installation of package 3a i am encoutering some trouble.
i was able to comlete the first part of the installation i receive
this error message: Instance name specified is invalid
so, my question is: once you have SQL Server installed, where can you
|
by: mr_burns |
last post by:
hi there,
Ive been having a few problems recently with this group. Im not sure
if any of the other groups have been giving me trouble but recently
this one has a couple of times, when attempting to reply, given me the
message 'Unable to retrieve message
rccharles-80ED6A.14593808012005@individual.net'.
Has anybody else had any similar problems?
|
by: ed |
last post by:
i'm having trouble with a form. I want to be able to type in the address of
the form with the data for the form items in the URL (ie:
http://somesite.com/formpage.html?field1=data1&field2=data2).
It saves the data if I type it in manually to an html file. But it won't do
that if I use the URL notation above. How do I get it to do this. The HTML
for the form is below.
Thank in advance,
ed
|
by: Lauren Wilson |
last post by:
I'm having trouble with the Access VBA help on my installation of A2K
with Dev tools. Every time I try to retrieve help for items listed in
the Object Browser (and SOME other items as well), Access tells me
that the "feature is broken" and prompts me to repair it. When I do
so, it goes through the motions but does NOT repair the help files.
Anyone have a clue about this problem?
| |
by: Jozef |
last post by:
Hello,
I am trying to put together a module and open a workspace on a database that
has a simple password (using Access XP). This is the lin that I'm having
trouble with;
Set wrk = CreateWorkspace("TestWrkspc", "Admin", conDbPwd)
conDBPwd is a variable that contains the password. There is no independant
workgroup file, just the default. This is the error message I'm getting;
|
by: Jozef |
last post by:
Hello,
I'm having trouble with the download links on my web server. The error I'm
getting is;
CGI Timeout
The specified CGI application exceeded the allowed time for processing. The
server has deleted the process.
It's a fresh Windows 2000 server install, but I also installed the ASP.net
|
by: Jozef |
last post by:
Hello.
I'm having trouble creating a blank solution (and ASP.net web application)
from my laptop. I own the server (in fact it's sitting right next to me)
and have added the URL to the trusted sites on my laptop. Here are the
details;
This is what I'm selecting from the start page....
>Add New Blank Solution
>Visual Basic Projects,
|
by: suzee_q00 |
last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it. Here's the code:
while ( ( fgets ( buf, BUFLEN, fin ) ) != NULL ) /* pulls a line from "fin" up to the length of BUFLEN and stores it in "buf" */
{
rmNl ( buf ); /* remove new line */
if ( !lineWithBlanks ( buf ) )
{
for (i = 0; buf !=...
|
by: Stu |
last post by:
Hi guys,
I've been having trouble getting the clock function to work portably,
please could I get some thoughts?
<Possibly OT comments>
It works fine on my laptop (under WinXP) and on my office computer
(under Linux), but I have to write some code for the system simulator
for the Cell BE processor (the thing inside the PS3), which is
apparently a PPC architecture, and I can't get the clock function to
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |