- 主题
- 9
- 帖子
- 74
- 精华
- 0
- 积分
- 204
- C币
- 187 枚
- 在线时间
- 17 小时
- 注册时间
- 2011-3-3
- 最后登录
- 2012-1-6
- 性别
- 男
 
- 主题
- 9
- 帖子
- 74
- C币
- 187 枚
- 在线时间
- 17 小时
|
发表于 2010-6-10 10:11:53
|显示全部楼层
/*记录句子中单词的首地址,此源代码已在vc++6.0中编绎通过,应该达到了你的要求*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
FILE *fp1,*fp2;
char ch;
int flag=1;
if((fp1=fopen("x.txt","r"))==NULL) //注意打开文件的格式,源文本文件放在vc运行此代码的工程文件中.
{
fprintf(stderr,"cann't open the file.\n");
exit(1);
}
if((fp2=fopen("x1.txt","w"))==NULL)
{
fprintf(stderr,"can't open the file.\n");
exit(2);
}
while((ch=getc(fp1))!=EOF)
{
if(isalpha(ch)&&flag)
{
flag=0;
printf("%p\n",fp1->_ptr); //FILE是一个结构,具体看stdio.h中的定义
fprintf(fp2,"%p",fp1->_ptr);
}
if(isspace(ch)||ispunct(ch))
flag=1;
}
fclose(fp1);
fclose(fp2);
return 0;
} |
|