[問題] 雙重指標
#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);
count=process(fp1, fp2);
output(count);
}
--------------------------------------------------------------------
這個程式目的是在一篇文章中搜尋關鍵字,我想問的是為什麼在input裡要用
**pfp1這種雙重指標? 在process裡開檔就好了不是嗎? 這樣做有什麼用意嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.208.139
→
02/18 21:11, , 1F
02/18 21:11, 1F
→
02/18 21:12, , 2F
02/18 21:12, 2F
→
02/18 21:13, , 3F
02/18 21:13, 3F
→
02/18 21:13, , 4F
02/18 21:13, 4F
→
02/18 21:41, , 5F
02/18 21:41, 5F
→
02/18 21:44, , 6F
02/18 21:44, 6F
→
02/18 21:46, , 7F
02/18 21:46, 7F
→
02/18 21:47, , 8F
02/18 21:47, 8F
→
02/18 21:48, , 9F
02/18 21:48, 9F
→
02/18 21:48, , 10F
02/18 21:48, 10F
→
02/18 23:31, , 11F
02/18 23:31, 11F
→
02/19 00:34, , 12F
02/19 00:34, 12F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章