问题描述
好吧,我读过一些几个月前又一个众所周知C书(在我的语言),我从来没有learn't这个没什么。 。该K&放的方式; R写入20页3章这是简直太神奇了,当然,我不能指望巨大的解释,但也上升问题
我有一个关于这点1.5.1问题
书上说的(PAG 16):
的main(){
INT℃; //< - 这是个问题
C =的getchar();
而(C!= EOF){
的putchar(C);
C =的getchar();
}
}
After searching google for another explanation:
So i modified source from int to char to see what is the problem, about taking EOF values... but there is no problem. Works the same way.
I also didn't undestrood how does getchar takes every character i write, and prints everything. Int type is 4bytes long, so it can take 4 characters inside a variable.But i can put any number of characters, it will read and write everything the same way.And with char, happens the same...What does really happens? Where are the values stored when there are more than 1-4 characters?
I happens to work the same way. It all depends on the real type of char
, i.e. if it's signed or unsigned. There's also a C FAQ about this very subject. You're more likely to see the bug if your char
s are unsigned.
EDIT
Each character will be stored by c
in turn. So the first time, getchar()
will return s
, and putchar
will send it on its way. Then t
will come along and so on. At no point will c
store more than one character. So although you feed it a large string, it deals with it by eating one character at a time.
这篇关于K&安培; R C语言程序设计1.5.1(文件复制)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!