认真地与C斗争 [英] Seriously struggling with C

查看:56
本文介绍了认真地与C斗争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候朋友,


本学期我开始了C编程课程。我一直在移动

直到我达到循环的主题(感觉很尴尬

你们精英程序员)。我的教授。会在线发布计划问题

和解决方案。为了练习,我会尝试解决问题。

我会达到代码中的某一点,例如,只要

错误捕获,但是当循环到达时,就像知道是否使用

一样,如何正确使用增量和减量,以及

计数器,我只是不精通它而且课程是继续前进。

最终我必须看看解决方案,并且想知道我自己想要了什么,这是我无法想到的原因。让我感到惊讶的是,

其他孩子很容易得到这些东西,而我有一个很难的b $ b时间。请告诉我我应该采取什么行动。我想

特别想知道在给定程序写入时参与

的思考过程。

感谢你的时间和考虑。


RG

Greetings friends,

This semester I have started a course in C programming. I was moving
along fine until I reached to the topic of loops (feeling embarrassed
among you elite programmers). My prof. would post program questions
and the solutions online. For practice I would try to do the problems.
I would reach to a certain point in the code, for example as far as
error trapping, but when the loop arrives, like knowing whether to use
for, while do, how to properly use the increment and decrements, and
counters,I am just not proficient in it and the class is moving ahead.
Eventually i would have to look at the solution and wondering to
myself, the reason i could not think of it. What ticks me off is that
other kids are getting this stuff easily, while I am having a hard
time.Kindly advise me on what actions I shoul take. I would
particularly like to have an idea of the thought process to engage in
when given the programme to write.
Thanks for your time and consideration.

RG

推荐答案

嗨!

我不是编程方面的专家,但我确实喜欢编程,因为它是b $ b精神刺激。我要告诉你的第一件事就是不要把你自己与别人比较,一旦你开始这样做,你就会感觉更糟糕。

尝试像游戏一样看编程。首先,尝试从数学角度构建自己的

解决方案,而不考虑C编程的

约束。我不会说它会很容易,但是给它一两次b / b
。尝试编写一个算法,我不会使用它们,但是它确实有助于理解程序的流向。所以

一旦你的解决方案尝试用你自己的话写。然后

最后使用编程语言的语法并在你的编辑器中试用它。

我不知道这会有多少帮你。我自己是新生,我​​只是告诉你我看到的方式。
。只是把它作为一个挑战,我是

确定你会没事的。

保重和好运。

Priyam

Hi!
I am not an expert in programming but I do like programming as it is
"mentally stimulating." The first thing that I will tell you is don''t
compare yourselves with others, once you start doing that, you are
going to feel worse.
Try seeing programming like a game. First, try and build your own
solution from a mathematical perspective, without taking the
constraints of C programming. I wont say that it will be easy, but give
it a shot. Try to write an alogorithm, I dont use them much, but it
does help to understand the direction in which the program flows. So
once you have your solution try writing it in your own words. And then
in the end use the syntax of the programming language and try it out in
your editor.
I dont how much this will help you. I am a freshman myself, and I am
just telling you the way I see it. Just take it as a challenge and I am
sure you will be fine.
Take care and Good Luck.
Priyam


RG写道:
RG wrote:
本学期我开始了C编程课程。我一直在移动,直到我达到循环的主题(在你们的精英程序员中感到尴尬)。我的教授。会在线发布程序问题和解决方案。为了练习,我会尝试解决问题。
我会达到代码中的某一点,例如,就错误捕获而言,但是当循环到达时,就像知道是否使用
for,while do,如何正确使用增量和减量,以及
计数器,


您问题的一个原因可能是没有明确的权利或

错误答案。你可以做一些while()你可以做一个

for(),

和for()的功能可以用while()复制还有一些其他的陈述。


。 C'代表()是非常强大的(有些可能是b


太强大了)。我倾向于将循环分为两种主要类型。


- 一个固定的已知迭代次数(循环次数),对于这些


用于()

- 迭代直到满足某些条件


//循环n次

for(i = 0; i< n; i ++)

do_something();


我只是将它作为一个样板代码学习当你需要一个

已知的迭代次数时才会进入。


//循环,而某些条件保持
while(条件)

do_something();


你可以用这两个做任何事情。

最后还有一段时间: -


做{

do_something()

}

而(条件);


但实践这一点远没那么有用。请注意,它总是至少支持
一次迭代。


用于循环的AC惯用语永远


for(;;)//永不停止

{

do_something();

if(exit_condition)

休息;

do_something_else();

}


这有时候很有用,我会避免它直到你很舒服

前两种形式。


C可能令人困惑的是聪明时of()的开头是

被利用。


//走一个链表

for(i = head; i! = NULL; i = i-> next)

flop_node(i-> data);


如果这让您感到困惑,请使用while()


for(i = 1,j = 1; i< k,j< l; i ++,j + 2)

something_scary(i, j);


如果这让你感到困惑...将程序列表分成小块并且

将它给它

到代码作者:-)


Keep It Simple是第一个编程的绝杀

我只是不精通它并且课程正在向前发展。
最终我必须看看解决方案并想知道自己,我无法想到它的原因。让我感到震惊的是,其他孩子很容易得到这些东西,而我的时间很难。请告诉我我应该采取什么行动。我特别希望在给定程序编写时能够了解参与
的思考过程。
This semester I have started a course in C programming. I was moving
along fine until I reached to the topic of loops (feeling embarrassed
among you elite programmers). My prof. would post program questions
and the solutions online. For practice I would try to do the problems.
I would reach to a certain point in the code, for example as far as
error trapping, but when the loop arrives, like knowing whether to use
for, while do, how to properly use the increment and decrements, and
counters,
one cause of your problems may be that there is no definitive right or
wrong answer. Anything you can do with a while() you can do with a
for(),
and the functionality of a for() can be duplicated with a while() and a

couple of other statements. C''s for() is very powerful (some might
argue,
too powerful). I tend to classify loops into two main types.

- a fixed known number of iterations (times around the loop), for these
I
use for()
- an iterate until some condition is met

// loop n times
for (i = 0; i < n; i++)
do_something ();

I''d just learn this as a piece of boilerplate code to drop in when you
need a
known number of iterations.

// loop while some condition holds
while (condition)
do_something();

You can pretty much do anything with those two.
There is also a while at the end:-

do {
do_something()
}
while (condition);

but it practice this is far less useful. note it always does at least
one iteration.

A C idiom for a loop that goes "forever"

for (;;) // never stops
{
do_something();
if (exit_condition)
break;
do_something_else();
}

this can sometimes be useful, I''d avoid it until you are comfortable
with the first two forms.

Where C can be confusing is when the "cleverness" of the for() is
exploited.

// walk a linked list
for (i = head; i != NULL; i = i->next)
flop_node (i->data);

If this confuses you, use a while()

for (i = 1, j = 1; i < k, j < l; i++, j + 2)
something_scary (i, j);

if this confuses you... chop the program listing into little pieces and
feed it
to the author of the code :-)

Keep It Simple is the first lore of programming
I am just not proficient in it and the class is moving ahead.
Eventually i would have to look at the solution and wondering to
myself, the reason i could not think of it. What ticks me off is that
other kids are getting this stuff easily, while I am having a hard
time.Kindly advise me on what actions I shoul take. I would
particularly like to have an idea of the thought process to engage in
when given the programme to write.



-

Nick Keighley


相当于fgets的fscanf非常简单

它可以在需要的时候内联使用: -

char s [NN + 1] ="",c;

int rc = fscanf(fp,"%NN [^ \ n]%1 [\ n]", s,& c);

if(rc == 1)fscanf("%* [^ \ n]%* c);

if(rc == 0)getc(fp);


--
Nick Keighley

The fscanf equivalent of fgets is so simple
that it can be used inline whenever needed:-
char s[NN + 1] = "", c;
int rc = fscanf(fp, "%NN[^\n]%1[\n]", s, &c);
if (rc == 1) fscanf("%*[^\n]%*c);
if (rc == 0) getc(fp);


RG写道:
问候朋友,

这个学期我开始了C编程课程。我一直在移动,直到我达到循环的主题(在你们的精英程序员中感到尴尬)。我的教授。会在线发布程序问题和解决方案。为了练习,我会尝试解决问题。
我会达到代码中的某一点,例如,就错误捕获而言,但是当循环到达时,就像知道是否使用
for,while do,如何正确使用增量和减量,以及
计数器,我只是不精通它并且课程正在向前推进。
最终我将不得不看看解决方案并且想知道自己,我无法想到它的原因。让我感到震惊的是,其他孩子很容易得到这些东西,而我的时间很难。请告诉我我应该采取什么行动。我特别想知道在给定程序编写时参与
的思考过程。
感谢您的时间和考虑。
Greetings friends,

This semester I have started a course in C programming. I was moving
along fine until I reached to the topic of loops (feeling embarrassed
among you elite programmers). My prof. would post program questions
and the solutions online. For practice I would try to do the problems.
I would reach to a certain point in the code, for example as far as
error trapping, but when the loop arrives, like knowing whether to use
for, while do, how to properly use the increment and decrements, and
counters,I am just not proficient in it and the class is moving ahead.
Eventually i would have to look at the solution and wondering to
myself, the reason i could not think of it. What ticks me off is that
other kids are getting this stuff easily, while I am having a hard
time.Kindly advise me on what actions I shoul take. I would
particularly like to have an idea of the thought process to engage in
when given the programme to write.
Thanks for your time and consideration.




请举例说明你不了解的事情。 while循环

可能是最容易理解的循环结构。


示例:


/ *显示长度为len的数组a的内容。 * /

k = 0;

while(k< len){

printf("%d \ n",a k]);

k ++;

}

/ *只要看一下循环守卫,就知道k> = len这里

(实际上是k == len)。 * /

八月


-

我是ILOVEGNU签名病毒。只需将我复制到您的

签名即可。此电子邮件受到GNU

通用公共许可证条款的影响。



Please, provide an example of something you don''t grasp. The while loop
is probably the easiest loop construct to understand.

Example:

/* Show the contents of the array a of length len. */
k = 0;
while (k < len) {
printf("%d\n", a[k]);
k++;
}
/* Just by looking at the loop guard, we know that k >= len here
(actually k == len). */
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.


这篇关于认真地与C斗争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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