⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 findfile.cpp

📁 VC源代码大全(精华版)
💻 CPP
字号:
/*
    findfile.cpp - search the include path for a specified
                   file.
 */
#include       <stdio.h>
#include       <io.h>
#include       <errno.h>
#include       <windows.h>
#include       <winbase.h>

#define    INCLUDEPATH         "INCLUDE"
#define    EXISTS              0

bool exist (char *pszFileName);

int main (int argc, char *argv[])
{
char *pszInclude;

    if (argc < 2)
    {
        fprintf (stderr, "Please name a file to find\n");
        return (-1);
    }
    char *pszFile = argv[1];
    int len = GetEnvironmentVariable (INCLUDEPATH, NULL, 0);
   if (!len)
    {
        fprintf (stderr, "Could not find include path\n");
        return (-1);
    }
    pszInclude = new char [len + 1];
    if (pszInclude == NULL)
    {
        fprintf (stderr, "Memory error\n");
        return (-1);
    }
    GetEnvironmentVariable (INCLUDEPATH, pszInclude, len + 1);
    char *s = strtok (pszInclude, ";");
    if (s == NULL)
    {
        fprintf (stderr, "Include path is empty\n");
        delete [] pszInclude;
        return (0);
    }
    do
    {
        char *str = new char [strlen(s)+strlen(pszFile)+2];
        if (str == NULL)
            continue;
        sprintf (str, "%s\\%s", s, pszFile);
        if (exist(str))
        {
            printf ("FOUND IT!!!\n%s\n", str);
            delete [] str;
            break;
        }
        printf ("%s was not found\n", str);
        delete [] str;
    } while ((s = strtok (NULL, ";")) != NULL);
    delete [] pszInclude;
    return (0);
}

bool exist (char *pszFile)
{
    int nExists = access ((const char *) pszFile, EXISTS);
    if (!nExists)
        return (true);
// Is it there and we just can't get to it?
    if (errno == EACCES)
        return (true);
    return (false);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -