Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请教关于carriage return(ASCII code 13)的问题

Posted by blablabla at 2007-01-29 12:49:01 on Problem 2418
我把输入文件复制到本地文件input.in:

Red Alder
Ash
Aspen
Basswood
Ash
Beech
Yellow Birch
Ash
Cherry
Cottonwood
Ash
Cypress
Red Elm
Gum
Hackberry
White Oak
Hickory
Pecan
Hard Maple
White Oak
Soft Maple
Red Oak
Red Oak
White Oak
Poplan
Sassafras
Sycamore
Black Walnut
Willow

然后把stdin重定向到input.in,这时读出的每一行字符都在‘\0’前加了一个carrige return,比如读入Ash,
char str[31];
gets(str);
这时str中的元素是:'A' 's' 'h' CR '\0'
其中CR代表carrige return
我自己实现了一个gets:while( ch=getchar() && ch!='\n') str[i++] = ch;
仍然会在'\n'前读入一个CR

这时怎么回事?

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator