易截截图软件、单文件、免安装、纯绿色、仅160KB

090928日c语言学习日记(文件I/O)

#include<stdio.h>
#include<stdlib.h>
#define MAX 41
static int i=0;
int main(void)
{
FILE *fp;
char words[MAX];
if((fp=fopen("words","a+"))==NULL)
{
fprintf(stdout,"Can't open \" word\" file\n");
exit(1);
}
puts("Enter words to add to the file,press the enter.");
puts("Key at the begining of a line to terminate.");
while(gets(words)!=NULL&&words[0]!='\0')
{
fprintf(fp,"%s",words);
i++;
}
rewind(fp);
while(fscanf(fp,"%s",words)==1)
{
puts(words);
}
if(fclose(fp)!=0)
{
fprintf(stderr,"Error closing file.\n");
}
return 0;
}

#include<stdio.h>
#include<stdlib.h>
#define MAX 2000
int main(void)
{
FILE *fp;
char words[MAX];
int wordct=0;
if((fp=fopen("words","a+"))==NULL)
{
fprintf(stderr,"Can't open \" word\" file\n");
exit(1);
}
rewind(fp);
while (fgets(words, MAX - 1, fp) != NULL)
wordct++;
rewind(fp);
puts("Enter words to add to the file,press the enter.");
puts("Key at the begining of a line to terminate.");
while(gets(words)!=NULL&&words[0]!='\0')
{
fprintf(fp,"%d:%s",++wordct,words);
}
puts("File contents:");
rewind(fp);
while(fgets(words,MAX-1,fp)!=NULL)
{
fputs(words,stdout);
}
if(fclose(fp)!=0)
{
fprintf(stderr,"Error closing file.\n");
}
return 0;
}
/*文件名由用户输入,建立一个循环,让用户输入文件位置,
则打印位置到下一个换行符之间的字符,当输入非数字字符时退出*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 41
int main(void)
{
FILE *fp;
char ch;
char file[MAX];
long address;
puts("请输入文件名");
gets(file);
if((fp=fopen(file,"rb"))==NULL)
{
fprintf(stderr,"Can't open the %s\n",file);
exit(1);
}


printf("请输入一个文件位置\n");
while(1)
{
scanf("%ld",&address);
if(isdigit(address))
{
break;
}
fseek(fp,address,SEEK_SET);

while((ch=getc(fp))!='\n' && (ch=getc(fp)


相关文档:

C技巧拾遗~

1. 怎样建立和理解非常复杂的声明?例如定义一个包含N 个指向返回指向字符的指针的函数的指针的数组?
这个问题至少有以下3 种答案:
1. char *(*(*a[N])())();
2. 用typedef 逐步完成声明:
typedef char *pc;  /* 字符指针*/
typedef pc fpc(); /* 返回字符指针的函数*/
typedef fpc *pfpc; /* 上面函数的指针*/ ......

C遗留的结构跳转 北海

1)          goto
goto 只能在一个函数内跳转。建议少用,使得程序维护起来容易出错;但是,在有多个循环情况下跳转,有时用goto可以使得问题变得简单。
class A
{
public:
A(){}
~A(){}
};
           &nbs ......

C指针之美一:神奇的函数

void mystery(int n)
{
 n += 5;
 n /= 10;
 printf(" :%s\n","***********" + 10 -n);
}
当一个字符串常量位于一个表达式中时,它的值是一个指针常量。编译器把这些指定字符的一份拷贝存储在内存的某个位置,并存储一个指向第1个字符的指针。但是,当数组名用于表达式中时,他们的值也是一个指针常量 ......

C/C++头文件一览


C/C++
头文件一览

//////////////////////////////////////////////////////////////////////////
C
头文件
(C89,C95)
(C++98,C++03也包含)
include <assert.h>    //诊断库
include <ctype.h>     //字符处理函数库
include <errno.h>     //错误定义
include <float.h& ......

C static

  C语言程序可以看成由一系列外部对象构成,这些外部对象可能是变量或函数。而内部变量是指定义在函数内部的函数参数及变量。外部变量定义在函数之外,因此可以在许多函数中使用。由于C语言不允许在一个函数中定义其它函数,因此函数本身只能是“外部的”。
      由于 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号