linux :

gcc exp_search.c -o exp_search

error: string: No such file or directory

atoll: 名词环礁 , 环状珊瑚岛

exp_search.c 

代码如下:

#include <string>
#include <stdio.h>
#include <stdlib.h>


using namespace std;


string fn_strGetSubContentFromFile(FILE *fp,long long loff,long long llen);


int main(int argc,char *argv[]){
    if(argc<4){
        printf("请依次指定[文件名] [偏移量] [长度]作为参数,此文件可以输出某文件的指定位置、指定长度的内容.\n");
        return 1;
    }
    long long loff=atoll(argv[2]);
    long long llen=atoll(argv[3]);
    FILE *fp=fopen(argv[1],"r");
    if(fp==NULL){
        printf("指定的文件名无法打开,请确认路径、是否可读等:%s.\n",argv[1]);
        return 1;
    }
    string res=fn_strGetSubContentFromFile(fp,loff,llen);
    printf("%s",res.c_str());
    if(fclose(fp)!=0){
        printf("关闭文件怎么失败了,不应该有的情况.\n");
        return 1;
    }
    return 0;
}
string fn_strGetSubContentFromFile(FILE *fp,long long loff,long long llen){
    string res;
    int ires=fseek(fp,loff,SEEK_SET);
    if(ires!=0){
        printf("发生了错误,根据指定的文件位置读不到任何内容.\n");
        return "";
    }
    char *buff;
    size_t result;
    buff=(char*)malloc(sizeof(char)*(llen+1));
    if(buff==NULL){
        printf("内存分配失败,这种错误可是很少出现的.\n");
        return "";
    }
    result=fread(buff,1,llen,fp);
    if(result!=llen){
        printf("这种情况也不应该出现,没有读到应有的字节数.");
        return "";
    }
    buff[llen]=0;
    res=buff;
    free(buff);
    return res;
}
原因是:这是个 .cpp 文件,不是  .c  文件。改为:

g++ exp_search.cpp -o exp_search

./exp_search  hello.c  6  8

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:30 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐