遇到麻烦 [英] Having Trouble

查看:68
本文介绍了遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从C编程语言中学习C语言。 (由K& R)和我

大约是第一章的一半。


我使用Miracle C作为我的文本编辑器和编译器。 />

到目前为止,一切正常,但现在这本书已经开始使用行和字计数程序了。我正在文本编辑器中输入

程序,就像它们在书中一样,

它们根本不能正常工作。他们编译得很好,当我运行

时,他们不会像他们应该那样产生任何输出。很奇怪。

我想它可能是我的编译器。有人推荐我使用DJPGG(我认为它被调用了)我尝试安装并运行该程序但是

这似乎是让我复杂的方式而且我有没有人能够

告诉我如何让它正常运行。


这是计算Prog的行:

#include < stdio.h>

main()

{

int c,nl;

nl = 0 ;

while((c = getchar())!= EOF)

if(c ==''\ n'')

++ nl;

printf("%d \ n",nl);

}


当我在cmdprompt中键入内容它不会给我任何输出(

i猜它被调用)它几乎就像printf cmd不在那里它

只是接收数据和没有显示任何东西这个单词

计数程序基本相同,并给了我相同的结果。

我输入的东西,点击输入而不是在
$ b上打印任何东西$ b屏幕暂停一会然后下移到下一行。

令人沮丧。还有wc程序直接来自本书中的
UNIX,当我将完全按照

书中的代码输入到我的编译器中时,我得到一个奇怪的错误喜欢它认为这个词OUT

是数字0.很奇怪....


我认为问题是我的编译器。任何人都可以推荐一款好的和/ b $ b易于使用的C编译器/文本编辑器吗?

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

推荐答案

ext_u写道:
ext_u wrote:

这是计算Prog的行:
#include< stdio.h>
main()
{
int c,nl;
nl = 0;
while((c = getchar())!= EOF)
if(c ==''\ n'')
++ nl;
printf("%d\ n",nl);
}

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

返回0;

}


这种类型的程序采用标准输入的输入文件,所以你

基本上需要将文件重定向到你的程序。


示例:

[hildrum:C-Programming] tor%wc -l linecount.c

18 linecount.c

[hildrum :C-Programming] tor%。/ linecount< linecount.c



Tor



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写道:
我正在尝试从C编程语言中学习C语言。 (由K& R提供)和我
大约在第一章的中间。

我使用Miracle C作为我的文本编辑器和编译器。

直到这一点一切正常,但现在这本书开始进行Line和Word计数程序了。我正在进入文本编辑器中的
程序,就像它们在书中一样,并且它们根本不能正常工作。它们编译得很好,当我运行它们时,它们不会像它们应该那样产生任何输出。很奇怪。
我想这可能是我的编译器。有人推荐我使用DJPGG(我认为它被称为)并且我试图安装并运行该程序但是这似乎是让我感到困惑的方式而且我没有谁可以展示
我如何让它正常运行。

这是计算Prog的行:
#include< stdio.h>
main()
{
int c,nl;
nl = 0;
while((c = getchar())!= EOF)
if(c ==''\ n'')
++ nl;
printf("%d \ n",nl);
}
当我在cmdprompt中输入内容时它不会给我任何输出(我猜它被称为)它几乎就像printf cmd不存在而且
只是接收数据而不显示任何内容。单词
计数程序基本相同,给了我相同的结果。
我输入一些内容,点击输入,而不是在
屏幕上打印任何东西,它暂停一会然后向下移动到下一行。
令人沮丧。还有wc程序直接来自本书中的UNIX,当我将代码完全按照
书中的代码输入到我的编译器中时,我得到一个奇怪的错误,就像它认为这个词一样OUT
我认为问题是我的编译器。任何人都可以推荐一款好用且易于使用的C编译器/文本编辑器??
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??




不,该程序是对的。它等着你发出EOF信号。

Control-Z应该适用于DOS。您可能必须按回车。


该程序可以通过发送文件来更好地阅读。


prog.exe< file.txt


在某处读取命令输出重定向,过滤器和管道。

我不知道一个好的概述,但它'一些基本的

知识。



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.


2003年8月17日18:19:07 -0700, ex *********** @ hotmail.com (ext_u)

写道:
On 17 Aug 2003 18:19:07 -0700, ex***********@hotmail.com (ext_u)
wrote:
我正在尝试从C编程语言中学习C语言。 (由K& R提供)和我
大约在第一章的中间。

我使用Miracle C作为我的文本编辑器和编译器。

直到这一点一切正常,但现在这本书开始进行Line和Word计数程序了。我正在进入文本编辑器中的
程序,就像它们在书中一样,并且它们根本不能正常工作。它们编译得很好,当我运行它们时,它们不会像它们应该那样产生任何输出。很奇怪。
我想这可能是我的编译器。有人推荐我使用DJPGG(我认为它被称为)并且我试图安装并运行该程序但是这似乎是让我感到困惑的方式而且我没有谁可以展示
我如何让它正常运行。

这是计算Prog的行:
#include< stdio.h>
main()
{
int c,nl;
nl = 0;
while((c = getchar())!= EOF)
if(c ==''\ n'')
++ nl;
printf("%d \ n",nl);
}
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);
}




你的问题可能是您需要在同一目录中的文本文件

作为您的可执行文件。只需在新文本文件中键入几行,或从某处复制

自述文件。然后在命令行输入:


" program_name" < " text_file_name"


然后你的程序会计算行数。


我相信这是你的问题。
< br $> b $ b比尔


Bill Reed

电子邮件=主题:必须包含clc



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


这篇关于遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆