K& R2第1.5.1节 - “getchar”问题 [英] K&R2 section 1.5.1 - "getchar" problem

查看:79
本文介绍了K& R2第1.5.1节 - “getchar”问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我稍微修改了1.5.1节中的程序,输入frm键盘需要

,然后将其输出到终端。它只是

没有运行,我无法理解错误信息。


你能告诉我出了什么问题以及如何做到这一点吗? br />

------------------------------ INPUT -------- -------------

#include< stdio.h>


int main(){

int c;


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

{

printf (你的输入:);

putchar(c);

printf(" \ n");

}


返回0;

}


-------------- ------- OUTPUT -----------------------------

[arch @ voodo kr2 ] $ gcc -ansi -pedantic -Wall -Wextra 151.c

151.c:1:错误:预期标识符或''(''''''''''''''' b $ b 151.c:2:12:错误:数字中的小数点太多

在/usr/include/_G_config.h:44中包含的文件中,

来自/usr/include/libio.h:32,

from /usr/include/stdio.h:72,

f rom 151.c:4:

/usr/include/gconv.h:72:错误:预期的声明说明符或

''''''''''''' size_t''

/usr/include/gconv.h:88:错误:预期声明说明符或

'''''''size_t''之前br />
/usr/include/gconv.h:97:错误:预期声明说明符或

'''''''size_t'''

/usr/include/gconv.h:174:错误:期望说明符 - 限定符列表
$'b $ b''size_t'之前'

包含在/ usr中的文件/include/stdio.h:72,

来自151.c:4:

/usr/include/libio.h:328:错误:期望说明符 - 限定符 - 清单
$'b $ b''size_t''

/usr/include/libio.h:360:错误:预期声明说明符或

'' ...''之前''size_t''

/usr/include/libio.h:369:错误:预期的声明说明符或

''......' '之前''size_t''

/ usr / i nclude / libio.h:485:错误:预期''='','','','';'',''asm''或

''__ attribute__'''之前'' '_IO_sgetn''

151.c中包含的文件:4:

/usr/include/stdio.h:306:错误:预期的声明说明符或
'b $ b'''''在''size_t''之前'

/usr/include/stdio.h:608:错误:预期''='','',' ''''''',''asm''或

''__ attribute__''在''fread'之前''

/usr/include/stdio.h: 614:错误:在''fwrite''之前预期''='','','','';'',''asm''或

''__ attribute__'' />
[arch @ voodo kr2] $

解决方案

gcc -ansi -pedantic -Wall -Wextra 151.c

151.c:1:错误:预期的标识符或''(''''''''令牌之前

151.c:2:12:错误:也是许多小数点数

In文件包含在/usr/include/_G_config.h:44,
来自/usr/include/libio.h:32的

来自/ usr / include / stdio的
。 h:72,

来自151.c:4:

/usr/include/gconv.h:72:错误:预期的声明说明符或
$ b $'''''''size_t''之前'

/usr/include/gconv.h:88:错误:预期的声明说明符或

'' ...''之前''size_t''

/usr/include/gconv.h:97:错误:预期声明说明符或

''......' '之前''size_t''

/usr/include/gconv.h:174:错误:期望说明符 - 限定符列表

之前''size_t''

来自/usr/include/stdio.h:72的文件,

来自151.c:4:

/ usr / include / libio .h:328:错误:期望说明符 - 限定符列表
$'b $ b''size_t''

/usr/include/libio.h:360:错误:预期声明说明者或

'''''在''size_t''之前'''
/usr/include/libio.h:369:错误:预期的声明说明符或

'''''''size_t'''

/usr/include/libio.h:485:错误:预期''='','','','';'',''asm''或

''__ attribute__' '之前''_IO_sgetn''

包含在151.c中的文件:4:

/usr/include/stdio.h:306:错误:预期的声明说明符或

'''''之前''size_t''

/usr/include/stdio.h:608:错误:预期''='',' ''','';'',''asm''或

''__ attribute__''在''fread'之前''

/ usr / include / stdio .h:614:错误:在''fwrite'之前预期''='','','','';'',''asm''或

''__ attribute__'' '

[arch @ voodo kr2]





3月8日,11日:上午07点,arnuld < geek.arn ... @ gmail.comwrote:


i稍微修改了1.5.1节中的程序,这需要

输入frm键盘,然后将其打印到终端。它只是

没有运行,我无法理解错误信息。


你可以告诉我有什么问题以及如何做到这一点?



参考此链接,
http://gcc.gnu.org/ml/gcc/2005-03/msg00865.html


if它与您的配置匹配(OS +编译器+库+标题)适用

最新补丁或需要。


>

------------------------------ INPUT -------------- -------

#include< stdio.h>


int main(){

int c ;


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

{

printf(" your input: ");

putchar(c);

printf(" \ n");

}


返回0;


}


---------------- ----- OUTPUT -----------------------------

[arch @ voodo kr2]

i have slightly modified the programme from section 1.5.1 which takes
the input frm keyboard and then prints that to the terminal. it just
does not run and i am unable to understand the error message.

may you tell me what is wrong and how to make that right ?

------------------------------ INPUT ---------------------
#include <stdio.h>

int main() {
int c;

while((c = getchar()) != EOF)
{
printf("your input: ");
putchar(c);
printf("\n");
}

return 0;
}

--------------------- OUTPUT -----------------------------
[arch@voodo kr2]$ gcc -ansi -pedantic -Wall -Wextra 151.c
151.c:1: error: expected identifier or ''('' before ''/'' token
151.c:2:12: error: too many decimal points in number
In file included from /usr/include/_G_config.h:44,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from 151.c:4:
/usr/include/gconv.h:72: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:88: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:97: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:174: error: expected specifier-qualifier-list
before ''size_t''
In file included from /usr/include/stdio.h:72,
from 151.c:4:
/usr/include/libio.h:328: error: expected specifier-qualifier-list
before ''size_t''
/usr/include/libio.h:360: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/libio.h:369: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/libio.h:485: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''_IO_sgetn''
In file included from 151.c:4:
/usr/include/stdio.h:306: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/stdio.h:608: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''fread''
/usr/include/stdio.h:614: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''fwrite''
[arch@voodo kr2]$

解决方案

gcc -ansi -pedantic -Wall -Wextra 151.c
151.c:1: error: expected identifier or ''('' before ''/'' token
151.c:2:12: error: too many decimal points in number
In file included from /usr/include/_G_config.h:44,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from 151.c:4:
/usr/include/gconv.h:72: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:88: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:97: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/gconv.h:174: error: expected specifier-qualifier-list
before ''size_t''
In file included from /usr/include/stdio.h:72,
from 151.c:4:
/usr/include/libio.h:328: error: expected specifier-qualifier-list
before ''size_t''
/usr/include/libio.h:360: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/libio.h:369: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/libio.h:485: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''_IO_sgetn''
In file included from 151.c:4:
/usr/include/stdio.h:306: error: expected declaration specifiers or
''...'' before ''size_t''
/usr/include/stdio.h:608: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''fread''
/usr/include/stdio.h:614: error: expected ''='', '','', '';'', ''asm'' or
''__attribute__'' before ''fwrite''
[arch@voodo kr2]





On Mar 8, 11:07 am, "arnuld" <geek.arn...@gmail.comwrote:

i have slightly modified the programme from section 1.5.1 which takes
the input frm keyboard and then prints that to the terminal. it just
does not run and i am unable to understand the error message.

may you tell me what is wrong and how to make that right ?

refer this link,
http://gcc.gnu.org/ml/gcc/2005-03/msg00865.html

if its match with your configuration (OS+compiler+libs+headers) apply
latest patch or do needful.

>
------------------------------ INPUT ---------------------
#include <stdio.h>

int main() {
int c;

while((c = getchar()) != EOF)
{
printf("your input: ");
putchar(c);
printf("\n");
}

return 0;

}

--------------------- OUTPUT -----------------------------
[arch@voodo kr2]


这篇关于K&amp; R2第1.5.1节 - “getchar”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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