比较atoi整数转换与int literal不工作

时间:2013-02-03 19:02:55

标签: c string atoi

我基本上有一个循环遍历字符串的函数,在每个字符处,函数使用atoi()函数将字符转换为整数,并将其发送到另一个验证此整数是否位于文件中的函数。但是它找不到str [] =“80”。

int isRegistered(FILE* fp, const char str[], char area[], char publisher[], char title[]){
    bool farea = false;
    char strtmp[6] = "";
    int len;
    for(int i=0; i <= sizeof(area) && farea == 0; i++){
        len = strlen(strtmp);
        strtmp[len] = str[i];
        strtmp[len+1] = '\0';
        farea = isRegistered(fp,atoi(strtmp));
    }
}

FILE* open(const char filename[]){
    return fopen(filename,"r");
}

int isRegistered(FILE* fp, int area){
    bool areafound = false, keepchecking = true;
    int areacheck;
    cout << "area : "  << area << endl;
    while(keepchecking && fscanf(fp, "%d %*[^ ] %*[^\n]", &areacheck) != EOF){
        if(areacheck == area){
            areafound = true;
            keepchecking = false;
            cout << ">>> Area found : " << areacheck << endl;
        }
    }
    close(fp);
    return areafound;
}

0 个答案:

没有答案