Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication59.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <cstring>
- #include <cctype>
- #include <algorithm>
- using namespace std;
- void SplitFilename(char* source, char* path, char* name, char* extension)
- {
- cout << source << " ";
- if (path[0] !='f') cout << "NULL" << " "; else cout << path << " ";
- if (name[0] != 'f') cout << "NULL" << " "; else cout << name << " ";
- if ((path[0] != 'f') && (name[0] != 'f')) cout << "NULL" << " ";
- else
- cout<< extension << " ";
- }
- int main()
- {
- char str[] = "d://folder//subfolder//file";
- int i, j, k, z, l;
- k = 0;
- char name1[100];
- char path1[100];
- char path[100];
- string g;
- for (i = 0; i<strlen(str); i++)
- {
- if ((str[i] == '.') && (str[i - 1] != '/'))
- {
- j = i; strncpy_s(path1, str, j);
- }
- }
- //cout << path1<<endl; /*d://folder//subfolder//file */
- for (i = j + 1; i<strlen(str); i++)
- {
- g =g+ str[i]; k++;
- }
- l = 1;
- j = 0;
- for (i = strlen(path1); i>0; i--)
- {
- if (path1[i] == '/')
- {
- j = i; break;
- }
- }
- l = j;
- //cout << extension<<endl; // беру всё что после . стоит с помощью отмеченой j
- if (l != 0){
- strncpy_s(path, path1, j + 1);
- }
- //cout << path <<endl;
- string b = path1;
- if (j != 0){
- b.erase(0, j + 1);
- }
- char * name = (char*)b.c_str();
- j = 0;
- for (i = 0; i<strlen(path); i++)
- {
- if (path[i] == '/') { break; }
- if (path[i] == '.') { j = i; break; }
- }
- if ((j = 0) || (strlen(name) == 0))
- {
- strncpy_s(name1, path, j);
- }
- char * extension = (char*)g.c_str();
- SplitFilename(str, path, name, extension);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement