由买买提看人间百态

topics

全部话题 - 话题: eof
首页 上页 1 2 3 4 (共4页)
b******d
发帖数: 794
1
来自主题: Java版 - 库存查询应该怎么做?
发现htmlunit也可以返回请求页面,不过现在访问一个页面老是报告这些warning, 有没
有办法去掉?
Oct 10, 2012 1:15:41 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerI
mpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Oct 10, 2012 1:15:41 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler
error
WARNING: CSS error: 'http://RSK.imageg.net/include/store.css' [324:75] Error
in style rule. (Invalid token "*". Was expecting one of: , , >, "}", ";".)
Oct 10, 2012 1:15:41 AM com.gargoylesoftware... 阅读全帖
C********a
发帖数: 10
2
想不明白BufferedReader.readLine()是怎么回事 如果是读文件的话,每叫一次
readLine()就读取文件的下一行,并且返回一个String;如果读到EOF就返回null。
比如
BufferedReader br = new BufferedReader("c:/test.txt");
while ((thisLine = br.readLine()) != null) {
System.out.println(thisLine);
}
那如果读的是一个inputstream呢 像下面
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userName = null;
try {
userName = br.readLine();
} catch (IOException ioe) {
System.out... 阅读全帖
s*****k
发帖数: 604
3
来自主题: Linux版 - grep 的问题
比如说我有个文件 a.txt
里面是这样的。
aaaa
1 2 3 4
bbbb
2 3 2 1
cccc
5 6 7 8
.
.
.
abcd
9 8 7 1
.
.
.
EOF
我想用grep 找到 abcd 那一行,然后显示 abcd 那一行和它的下一行,像这样
abcd
9 8 7 1
该如何做?
l****n
发帖数: 508
4
vi自身依赖一些模块,加起来比较庞大。有时候建系统不系望过大,就不装vi等编辑软
件,那需要编辑的时候自然就得用 cat > file.txt <<"EOF" 的 shell 形式了。
不得已而为之,于是否高手无关。
S*A
发帖数: 7142
5
不会用 csh.
bash 里面大概是
varname=`sqlplus -silent id/password@oracel_instance < printf("%s",$1;}'
"%s",$1;}' `

printf(
l*******G
发帖数: 1191
6
use ` ` or $()
such as
varname=$(sqlplus -silent id/password@oracel_instance < echo $varname
d********t
发帖数: 9628
7
来自主题: Linux版 - 越用越觉得c好用

那就直接cat << EOF一个python进去
d******i
发帖数: 7160
8
输入重定向(getline)
getline 函数用来从标准输入,例如管道或者文件来读入数据,而不是
从正被处理的当前文件。getline 取得输入的下一行,并更新NF、NR
和FNR等内置变量的值。如果getline找到记录则返回1,达到EOF(文
件结束)则返回0。如果有错误则返回-1。

举例1:
$ nawk 'BEGIN{"date"|getline d;print d}' datafile
2005年05月06日 星期五 15时05分41秒 CST
解释:执行date命令,然后把输出从管道送到getline,并赋给自
定义变量d,然后打印d。
— 举例2:
$nawk 'BEGIN{while("ls"|getline) print}'
awk.sc2
datafile
datafile2
employees
employees2
lab5.data
names
passwd
解释:将把ls的输出送到getline。对于每次循环,getline都从
ls读取一个以上输出,然后打印到屏幕上
好像getline不认得,运行不了。
X****r
发帖数: 3557
9
来自主题: Programming版 - [转载] 简单的题都不敢做了.
其实就按本来面目写也很清楚,不用写成一堆条件,还不用缓冲区。
int ch, branch, state = 0 ;
int table[][2] = { { 1, 0 }, { 2, 3 }, { '0', 3 }, { '1', 0 } };
while( (ch = getchar()) != EOF )
( ch == 'a' && (branch = 0, 1) || ch == 'b' && (branch = 1, 1) ||(state=0))&&
( (state = table[state][branch]) == '0' || state == '1' ) &&
( putchar( state ), state = 0 ) ;
加注:面试的时候可不要写这种code,没拿到offer 不要怪我……,
了解我的意思就行了:)
Q**g
发帖数: 183
10
来自主题: Programming版 - perl里面的seek怎么用呢?
"sysseek() bypasses normal buffered IO, so mixing this with reads (other
than sysread, for example <> or read()) print, write, seek, tell, or eof may
cause confusion."
so try sysread.

getc
t*********n
发帖数: 278
11
来自主题: Programming版 - code question
the sample from programming pearls. But, I got complier error at this line
qsort(a, n, sizeof(char *), pstrcmp). How can I fix this one? Thanx.
#include
#include
#include
int pstrcmp(char **p, char **q)
{ return strcmp(*p, *q); }
#define MAXN 5000000
char c[MAXN], *a[MAXN];
int main()
{ int i, ch, n = 0, maxi, maxlen = -1;
while ((ch = getchar()) != EOF) {
a[n] = &c[n];
c[n++] = ch;
}

c[n] = 0;
qsort(a, n, sizeof(char *), pstrcmp);
}
... ?I see that you need "跟肉眼符合的页面", so you need to parse the html into a
document tree and render it.
If the only thing you need is to strip out those tags quoted by "<" and ">",
then it's very easy. The following filter will do and should be very fast:
/*
* This program filters out all html tags quoted by '<' and '>'.
* @compile: gcc -o a a.c
* @use: ./a < x.html > x.txt
*/
#include
void main() {
char c;
int ok = 1;
while ((c = getchar()) != EOF) {
if (c == '<') ok = 0;
else
I**********s
发帖数: 441
12
来自主题: Programming版 - 如何下载网络页面,不包含,
I**********s
发帖数: 441
13
来自主题: Programming版 - python的一大缺点
My filter used to change tab to space:
/*
* @usage: ./filter [n]
* The optional n is the number of spaces to replace a tab.
* n default to 4.
*/
void main(int argc, char ** argv) {
char c;
int i, n = (argc > 1) ? atoi(argv[1]) : 4;
while ((c = getchar()) != EOF) {
if (c == '\t') { for (i = 0; i < n; i ++) putchar(' '); }
else { putchar(c); }
}
}
L*******g
发帖数: 913
14
来自主题: Programming版 - 低手问个C的scanf问题
程序里先有个
while(scanf("%d", &n)!=EOF) { .... }
然后想从键盘读入一串数,用
scanf("%d", &m);
程序运行的时候是用 ./a.out < list 的形式从list导入数据。但是这样就不能从键盘
输入,m的值自动就是list的最后一个数值。
请问如何才能从list读完数据以后再从键盘读数据?
j******e
发帖数: 64
15
来自主题: Programming版 - 问一个很弱的c++ cin的问题
EOF不是从file读入吗?我是从std::in读入
w******g
发帖数: 67
16
来自主题: Programming版 - question about "popen" in C/C++
When I use following code of "popen" to run some shell command in my C++
progarm under Linux, I get the output both on the terminal screen and in the
string variable. How can I ask popen stop putting output on the screen but
only in the string variable. Thanks.
// run the shell command and put the output into string
string FileOperation::runCommand(string command)
{
stringstream msg;
char c;

FILE *output = popen(command.c_str(),"w");
while( (c=fgetc(output))!= EOF )
{
g*********s
发帖数: 1782
17
来自主题: Programming版 - 多次调用yyarse()的buffer flush问题。
误打误撞,问题居然解决了。
第一个文件有个/*,但没有匹配的*/,就一直找到文件尾,然后报错返回。
下面这个方案经过验证可行:
<> {printf("unfinished comments when file ends\n"); YY_FLUSH_
BUFFER; BEGIN INITIAL; }
但对flex/bison这套错误处理机制还是不太清楚。
d***2
发帖数: 7
18
来自主题: Programming版 - windows script parameter with spaces
I've got some files named like "c:\data set0.txt", "c:\data set1.txt"... (
there is a space between "data" and "set"), how can i pass them as
parameters as in the following script.
REM ----begin------
for /F %%i in (`dir c:\*.txt`) do call :run_file "%%i"
goto :eof
echo %1
some_command %1
REM -----end -----
The console complains, and it seems, because of the file names are not
passed through complete to the procedure :run_file, but only the first part
of it "c:\data".
Can anyone here tell me how
l***e
发帖数: 480
19
来自主题: Programming版 - 继续请教C++重载问题,>>
like this?:
friend istream & operator>>(istream &stream, class & obj) {
i=getline(stream, obj.a, '\t');
if(i>0){
getline(stream, obj.b, '\t');
stream >> obj.c >> obj.d >> ws;
return stream;
}
}
mail()
{
while(!cin.eof()) cin>>obj;
}
e****d
发帖数: 333
20
来自主题: Programming版 - 问个程序问题
ifstream 里面重载了 operator>>.
ifstream::eof()判断结束。
array用new 实现。
完了。
j***3
发帖数: 142
21
来自主题: Programming版 - 请帮忙看一下这个c程序(更新)
请问main 里的这一段不是已经 考虑了new line的问题了吗,因为用window size 小于
行字符数时程序没有问题啊?
/** continue processing **/
while ((ch = getc(in)) != EOF)
{
/* remove contribution for nucleotide freq for first char */
index1 = indexMinus(win[0], &a, &c, &g, &t);
index2 = index(win[1]);
/* remove contribution for nucleotide freq for first char */
pair[index1][index2]--;
/* move things down in window */
for (i=0;i if
j***3
发帖数: 142
22
来自主题: Programming版 - 请帮忙看一下这个c程序(更新)
但是在 if 里面已经用ungetc push 了一次,在while 里又要 push一次吗?象这样:
/** continue processing **/
while ((ch = getc(in)) != EOF)
{
ungetc(ch, in);
/* remove contribution for nucleotide freq for first char */
index1 = indexMinus(win[0], &a, &c, &g, &t);
index2 = index(win[1]);
/* remove contribution for nucleotide freq for first char */
pair[index1][index2]--;
/* move things down in window */
for (i=0;i
t****t
发帖数: 6806
23
Usually it is used in context such as
while (cin>>something) {
...
};
as opposed to
while (cin) { // while (cin.isgood())
...
}
In fact, std::basic_ios has a lot of members to check state, such as
good(), eof(), fail(), bad(). You can call them explicitly if you want
to do that (actually bool(cin) == !cin.fail()). But usually this is not
correct:
while (cin) { // or while (!cin.fail())
cin>> something;
...
}
check C++ FAQ lite.
s*w
发帖数: 729
24
判断输入结束
while (!getline(cin,str,' ').eof()) {
}
string 转数字方法很多,随便 google, 比如
istringstream stream (s);
double t;
stream >> t;
g*********s
发帖数: 1782
25
来自主题: Programming版 - how to use cin as default ifstream?
the following code reads lines from the input file and skip the empty lines.
how to change the following code such that if argv[1] is not provided, we
use cin as default ifstream?
int main() {
vector lines;
ifstream input_file(argv[1]);
if ( input_file.is_open()) {
while ( !input_file.eof() ) {
string str;
getline(input_file, str);
if ( str.empty() ) {
continue;
}
else
{
... 阅读全帖
g*********s
发帖数: 1782
26
来自主题: Programming版 - how to skip the last empty lines in ifstream?
the following code will keep the empty line. but there's always an extra empty line at the end. any elegant solution to fix it?
int main() {
vector lines;
ifstream input_file(argv[1]);
if ( input_file.is_open()) {
while ( !input_file.eof() ) {
string str;
getline(input_file, str);
/*
if ( str.empty() ) {
continue;
}
else
*/
{
lines.push_back(str);
}
... 阅读全帖
H***a
发帖数: 735
27
来自主题: Programming版 - how to skip the last empty lines in ifstream?
The EOF is a bit tricky. It's easy to remember that:
** always check right after you attempt to read **
There are two solutions:
1)
...
if ( infile.is_open() )
{
string str("");
getline(infile, str); //read it first!!
while ( infile.good() )
{
lines.push_back(str);
getline( infile, str ); //now get the next line!
}
infile.close();
}
...
2) Simpler way which is recommended
...
if ( infile.is_open() )
{
string str("");
while ( getline(infile, ... 阅读全帖
d****n
发帖数: 1637
28
来自主题: Programming版 - c字符串内存分配问题
malloc, calloc, realloc are in HEAP
alloca is in STACK
#####example####
buffered IO with char input
################
n=0;m=1024
char *s=(char *)calloc(m, sizeof(char));
char c;
while((c=getch())!=EOF){
if(n==m) s=(char *)realloc(s, (m<<=1),sizeof(char) );
*(s+(n++))=c;
}
*(s+n)='\0';
printf("%s\n", s);
free(s);
d****n
发帖数: 1637
29
来自主题: Programming版 - 标 题: 发包子 echo 求助
if unknown number of paramers.
#include
#define MAX 1000
int main(){
int params[MAX];
int i=0,j, t;
while(scanf("%d",&t)!=EOF && i while(i>=0) printf("%d ", params[--i]);
}
////output1////
$ echo 1 2 3 4 5 6 7 8 |./a.out
8 7 6 5 4 3 2 1
///output2///
echo 1234 5678 9101 4567 | ./a.out
4567 9101 5678 1234
e********r
发帖数: 2352
30
来自主题: Programming版 - 请教一个C++的问题
为了使用try ... throw ... catch的方式处理异常,写了以下一段程序,就是读取一
个文件
ifstream file;
file.exceptions(ifstream::failbit | ifstream::badbit);
try{
file.open("./file");
string str;
while(getline(file, str))
{
cout< }
}
catch(ifstream::failure e)
{
cout<<"Return information: "< }
file.close();
请问为什么总是会执行catch... 阅读全帖
t****t
发帖数: 6806
31
来自主题: Programming版 - 请教一个C++的问题
我说的是EOF appear in the middle of line, 即最后一行无回车. 如果用vim打开的
话会提示incomplete last line.
k**********g
发帖数: 989
32
来自主题: Programming版 - 问一段C++ iostringstream的代码

http://www.cplusplus.com/reference/string/string/operator%3E%3E
http://www.cplusplus.com/reference/istream/istream/
http://www.cplusplus.com/reference/ios/ios/good/
Usually, istream::good() is used to check the stream's state, because
istream actually has three other non-good states: eof(), bad(), and fail().
The boolean cast is usually not good enough.
Your test code shows that it is necessary to clear the string prior to
reading. So, Line 19 is necessary anyway.
A simpler alternative is to de... 阅读全帖
o**2
发帖数: 168
33
这个协议是要用在messaging上的,就是说和有connection的通讯不大一样,比如你得
不到connection broken或EOF这样的额外信息,所有的信息就是message本身。
1,甲 >> MSG >> 乙
2,甲 << ACK << 乙
假设甲管钱,乙管车票。第一步就是甲给乙发一个MSG,这个MSG含有购一张票的信息。
如果乙有票的话,就库存减一,否则库存不变,这个结果放在ACK里返回。
第二步,甲收到这个ACK里的结果后,相应地扣钱:乙成功,扣钱;反之,不扣。
现在的问题是,在MSG/ACK有可能丢失的前提下,如何保证甲乙双方动作同步?比如,
ACK丢失了,结果乙扣了票,但甲没有扣钱。
如果象下面那样继续互相ACK下去,什么时候是结束的时候?
3,甲 >> ACK1 >> 乙
4,甲 << ACK2 << 乙
5,甲 >> ACK3 >> 乙
6,甲 << ACK4 << 乙
7,甲 >> ACK5 >> 乙
8,甲 << ACK6 << 乙
p*****2
发帖数: 21240
34
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
比如下边这段代码,怎么能好看一点?有什么trick吗?
func readUserCSV(file string, lambda func(string, string) error) error {
csvfile, err := os.Open(file)
if err {
return err
}
defer csvfile.Close()
reader := csv.NewReader(csvfile)
reader.Read()
_for:
for {
record, err := reader.Read()
switch err {
case nil:
if err = lambda(record[0], record[1]); err != nil {
return err
}
case io.EOF:
break _for
... 阅读全帖
d****n
发帖数: 1637
35
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
抛砖引玉
func readUserCSV(file string, lambda func(string, string) error) err error {
csvfile, err := os.Open(file)
if err {
return err
}
defer csvfile.Close()
reader := csv.NewReader(csvfile)
reader.Read()

for {
if err != nil{
if err == io.EOF{
err = nil
}
break
}

record, err := reader.Read()
if err !=nil{
continue
}

... 阅读全帖
d****n
发帖数: 1637
36
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
结尾没有return, at 9:17AM PCT
package main
import (
"encoding/csv"
"fmt"
"io"
"os"
)
func main() {
if err := readUserCSV("./test.csv", lambda); err != nil {
//do something
}
}
func readUserCSV(file string, lambda func(string, string) error) error {
csvfile, err := os.Open(file)
if err != nil {
return err
}
defer csvfile.Close()
reader := csv.NewReader(csvfile)
for {
record, err := reader.Read()
if err != nil {
... 阅读全帖
c*******0
发帖数: 5247
37
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?

switch?
csv parsing就两种情况,error和eof。error你要细分就是两种,ErrReadRune和
ErrQuote。你去哪找"if else多了"的情况?
你现在引入lambda之后,lambda会return err,这个是readUserCSV的caller应该去管
的,而不是readUserCSV去管的。
先把自己的需求搞清楚。
a***n
发帖数: 623
38
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
1 package main
2
3 import (
4 "encoding/csv"
5 "io"
6 "os"
7 )
8
9 func readUserCSV(file string, lambda func(string, string) error) error {
10 csvfile, err := os.Open(file)
11 if err != nil {
12 return err
13 }
14 defer csvfile.Close()
15
16 reader := csv.NewReader(csvfile)
17 reader.Read()
18
19 for {
20 record, err := reader.Read()
21 if err != nil &... 阅读全帖
d****n
发帖数: 1637
39
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
I would change lambda function signature to let less and clearer code in
readUserCSV logic; this will keep readUserCSV low maintain
for {
record, err := reader.Read()
if err != nil && err != io.EOF {
return err
}
if err = lambdaWrapper(record,Lambda); err != nil {
return err
}
}
}
func lambdaWrapper(record,Lambda){
if len(record)!=2{
return nil //not a big deal, pass it
}
//there is nothing else can crash before calling lambda
return lambda(record[0], re... 阅读全帖
e*****r
发帖数: 144
40
来自主题: Programming版 - 谁能告诉为啥最后为啥输出两个C
int main()
{
string s = "A B C "; // output is A B C C
// If string s = "A B C", then the output would be A B C
istringstream iss(s);
string temp;
while (!iss.eof())
{
iss >> temp;
cout << temp << endl;
}
}
So why an extra white space in s matters?
g*****y
发帖数: 7271
41
来自主题: Programming版 - 谁能告诉为啥最后为啥输出两个C
应该是读过了以后(iss >> temp)再check是否eof吧?
P***i
发帖数: 118
42
来自主题: Unix版 - 请诊断:
我有一台磁带机, 有次操作出现以下错误信息, 请问是何原因, 并请教解决方法, 多谢!
1. mt status
>
> SCSI 2 tape drive:
> File number=0, block number=0, partition=0.
> Tape block size 0 bytes. Density code 0x26 (unknown to this mt).
> Soft error count since last status=0
> General status bits on (41010000):
> BOT ONLINE IM_REP_EN
>
> 2. mt rewind
> (No result)
>
> 3. tar tv
> -rw-r--r-- eeg/users 11447200 2000-06-27 12:46:40 file/file1
> tar: Unexpected EOF on archive file
> tar: Error is not recoverable: exiting now
后来我又试用:
data> m
d*o
发帖数: 108
43
来自主题: Unix版 - [转载] Hidden character in a file
【 以下文字转载自 Programming 讨论区 】
【 原文由 duo 所发表 】
Need to understand the following questions to program in C/C++:
1. Does any text file always end with a '\n'? i.e. if a text file
contains only one character, any editor will automatically add
a '\n' at the end of a file?
2. Is there a charater in a text file called 'end of file'? Use
the above example, if a text file has only one character 'a',
how many characters for this file? i.e. is it 'a' + '\n'?
or is it 'a' + '\n' + '\eof'?
Thanks for all help!
e***o
发帖数: 14
44
来自主题: Unix版 - [转载] Hidden character in a file

no ( unless you hit the enter key
at least not in vi and emacs
EOF (end of file) is not a character.
So if you only type a in a new file, the there is only an a in this
file and nothing else.
t*********l
发帖数: 30
45
来自主题: Unix版 - some useful (hopefully) sed command
*double space a file
sed G
*under UNIX convert DOS newline (CR/LF) to Unix format:
sed 's/.$//'
sed 's/^M$//' #^M should be input like this: Ctrl-V Ctrl-M
*delete leading whitespaces
sed -e 's/^[ ^t]*//' #^t (table): Ctrl-V Ctrl-I
*delete all CONSECUTIVE blank lines from file except the first
sed '/./,/^$/!d' #this will allows 0 blank at top
#in (t)csh, you may want to use \!
sed '/^$/N;/\n$/D' #allowas 1 blank at top, 0 at EOF
*de
p******f
发帖数: 162
46
来自主题: Unix版 - Socket programming help

return value of mysocketread less than bytes is caused by unexpected
EOF on socket, which is not an error with regard to read(2), so errno
is not set in this case. you should only check errno when any syscall
returns error (normally -1).
m*******y
发帖数: 99
47
来自主题: Chemistry版 - 进了家新公司,要疯了
面试一顿吹牛,说我啥都会。
但是当时问了我van derr meet 方程 和EOF 我都没答上来。
b*******g
发帖数: 1309
48
来自主题: Chemistry版 - 进了家新公司,要疯了
不知道EOF, 你确认你是学微流控的?
哈哈
y*****s
发帖数: 1047
49
来自主题: Chemistry版 - 进了家新公司,要疯了
eof= electroosmotic flow?
首页 上页 1 2 3 4 (共4页)