获得文件路径 _pgmptr, _makepath, _splitpath

#include <stdlib.h>

#include <stdio.h>

int main(void)

{

    char path_buffer[_MAX_PATH];

    char drive[_MAX_DRIVE];

    char dir[_MAX_DIR];

    char fname[_MAX_FNAME];

    char ext[_MAX_EXT];

    _makepath(path_buffer, "c", "\\sample\\myprogarm\\","makepath", "txt" ); // C4996

    printf( "Path created with _makepath: %s\n", path_buffer );

    _splitpath( path_buffer, drive, dir, fname, ext ); // C4996

    printf("Path extracted with _splitpath:\n");

    printf("Drive: %s\n", drive );

    printf("Dir: %s\n", dir );

    printf("Filename: %s\n", fname );

    printf("Ext: %s\n", ext );

    return 1;

}

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

int main(int argc, char * argv[])
{
    char s[10] = {0};

    int strLen = strlen(_pgmptr);

    if (sizeof(s)/sizeof(s[0]) < strLen)
    {
        strLen = sizeof(s)/sizeof(s[0]);
    }

    memcpy(s, _pgmptr, strLen);

    s[sizeof(s)/sizeof(s[0])] = '\0';

    printf("\ns=%s\n", s);

    system("pause");
    return 0;
}

你可能感兴趣的:(split)