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

c获取文件的大小和文件属性、文件查找

1 fseek移动指针获取
#include <stdio.h>
#include <stdlib.h>
long filesize( FILE *fp )
{
    long int save_pos;
    long size_of_file;
    /* Save the current position. */
    save_pos = ftell( fp );
    /* Jump to the end of the file. */
    fseek( fp, 0L, SEEK_END );
    /* Get the end position. */
    size_of_file = ftell( fp );
    /* Jump back to the original position. */
    fseek( fp, save_pos, SEEK_SET );
    return( size_of_file );
}
int main( void )
{
    FILE *fp;
    fp = fopen( "aa.txt", "r" );
    if( fp != NULL ) {
        printf( "File size=%ld\n", filesize( fp ) );
        fclose( fp );
        return EXIT_SUCCESS;
    }
    return EXIT_FAILURE;
}
2 stat获取
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main( void )
{
struct stat buf;
if( stat( "file", &buf ) != -1 ) {
printf( "File size = %d\n", buf.st_size );
}
return EXIT_SUCCESS;
}
但是是有区别的,如
参考fseek()。
  通过fseek()、ftell()两个函数,我们就可以随意访问文件的任何位置了,想了想好像操作文件就这么easy,实在也没有更多可说的了。对了,fseek()和ftell()存在一个潜在的问题就是他们限制文件的大小只能在long类型的表示范围以内,也就是说通过这种方式,只能打开 2,000,000,000字节的文件,不过在绝大多数情况下似乎也已经够用了。如果需要打开更大的文件,你需要用到fgetpos()、 fsetpos()函数了,那是另一个命题了。
#include <stdio.h>
#include <string.h>
int main()
{
    int  i;
    long k;
    char buf[100];
    long int save_pos;
    FILE *fp;
  


相关文档:

c文件操作

#include <stdio.h>
#include <stdlib.h> //use malloc, free
#include <string.h> //use memset
#include <ctype.h> //use isdigit
#define ERROR_ILLEGAL_CHAR 1 //define error illegal character as 1
#define ERROR_NUMBERS_DIF 2 //define error numbers is not the same in diffe ......

Linux C 开发环境(debian)

#apt-get install gcc (编译器)
#apt-get install gdb (调试)
#apt-get install libc6-dev (开发库)
如果没有开发库,gcc的时候就会错误
gcc h.c
h.c: In function ‘main’:
h.c:1: warning: incompatible implicit declaration of built-in function ‘prin ......

C代码规范与运行时长分析模板

/*****************************************************
文件:main.c
功能:测试运行时间(C)!
作者:chinayaosir   QQ:44633197
工具:VC++6.0编译OK!
日期:11/28/2009
代码目录:
//1.包含头文件
//2.main主程序
//不同的算法实现的性能,运行时间相差非常大的!
修改列表:
***************** ......

通过JNI在JAVA与C程序中传递参数

一、编辑Java源文件
=============================================
Hello.java
=============================================
package test;
public class Hello
{
  static
  {
    try
    {
      //此处即为本地方法所在链接库名
&n ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号