作者walm20 (New CygnusX)
看板C_and_CPP
标题Re: [问题] 双重指标
时间Wed Feb 18 23:27:29 2009
※ 引述《hardman1110 (硬汉)》之铭言:
: #include <stdio.h>
: #include <string.h>
: void input(FILE **pfp1, FILE **pfp2)
: {
: char string[20];
: printf("请输入文章档名:");
: gets(string);
: *pfp1 = fopen(string,"r");
: printf("输入测试的字串:");
: gets(string);
: *pfp2 = fopen(string,"r");
: }
: void output(int count)
: {
: printf("出现了%d次\n",count);
: }
: int process(FILE *fp1, FILE *fp2)
: {
: int count=0;
: char st[20], word[20];
: fscanf(fp2,"%s",word);
: printf("Searching word=%s\n",word);
: while(fscanf(fp1,"%[^., ]",st)!=EOF)
: {
: if(strcmp(st,word)==0)
: {
: count++;
: }
: fscanf(fp1,"%[., ]",st);
: }
: return count;
: }
: void main(void)
: {
: FILE *fp1, *fp2;
: int count;
: input(&fp1, &fp2);
^^^^ ^^^^^
他想要对fp1跟fp2做input的引数
且传入参数方法为call by address(pointer)
这里如果懂得话
看input function里面就应该懂了
: count=process(fp1, fp2);
: output(count);
: }
: --------------------------------------------------------------------
: 这个程式目的是在一篇文章中搜寻关键字,我想问的是为什麽在input里要用
: **pfp1这种双重指标? 在process里开档就好了不是吗? 这样做有什麽用意吗?
--
我的露天拍卖:
http://tinyurl.com/6z4rw7
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.165.147.174
1F:推 VictorTom:Call by Address不就是Call by Reference吗?_? 02/19 00:04
2F:→ VictorTom:其实这个Call by Pointer应该是Call by Value吧@_@" 02/19 00:05
3F:→ walm20:call by ref function prototype void f(int &a); 02/19 00:14
4F:→ walm20: 呼叫 f(a); 02/19 00:14
5F:→ walm20:call by Pointer是不是call by value是看对哪个变数存取 02/19 00:16
6F:推 VictorTom:XD 原来func有换掉 XD 话说, C现在可以用C by Ref吗?? 02/19 00:16
7F:→ VictorTom:正式的说法里没有call by pointer这种讲法吧?? 02/19 00:17
8F:→ VictorTom:原po那个code的写法是标准的call by value才对.... 02/19 00:18
9F:→ VictorTom:by Addr, by Ptr之类的讲法, 很容易搞错说....@_@" 02/19 00:19
10F:→ walm20:call by XXX是要看 你对哪个变数做存取 02/19 00:19
11F:→ windincloud:楼上 不是吧~ 就只有三种呀 call by addr. val. & ref 02/19 09:54
12F:→ windincloud:没有call by pointer这样的说法吧~ 02/19 09:55
14F:→ windincloud:这边应该是call by addr. 传入pointer的addr. 02/19 10:00
15F:→ walm20:我推文中笔误 我是要说by addr. 我是觉得addr跟ptr是一样 02/19 11:32