Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. // ConsoleApplication59.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <string.h>
  8. #include <cstring>
  9. #include <cctype>
  10. #include <algorithm>
  11. using namespace std;
  12.  
  13. void SplitFilename(char* source, char* path, char* name, char* extension)
  14. {
  15.     cout << source << "  ";
  16.     if (path[0] !='f') cout << "NULL" << "  "; else cout << path << "  ";
  17.     if (name[0] != 'f') cout << "NULL" << "  "; else cout << name << "  ";
  18.     if ((path[0] != 'f') && (name[0] != 'f')) cout << "NULL" << "  ";
  19.     else
  20.     cout<< extension << "  ";
  21. }
  22.  
  23. int main()
  24. {
  25.     char str[] = "d://folder//subfolder//file";
  26.     int i, j, k, z, l;
  27.     k = 0;
  28.     char name1[100];
  29.     char path1[100];
  30.     char path[100];
  31.    
  32.     string g;
  33.     for (i = 0; i<strlen(str); i++)
  34.     {
  35.         if ((str[i] == '.') && (str[i - 1] != '/'))
  36.         {
  37.             j = i; strncpy_s(path1, str, j);
  38.         }
  39.  
  40.  
  41.     }
  42.     //cout << path1<<endl; /*d://folder//subfolder//file */
  43.  
  44.     for (i = j + 1; i<strlen(str); i++)
  45.     {
  46.         g =g+ str[i]; k++;
  47.     }
  48.  
  49.     l = 1;
  50.     j = 0;
  51.     for (i = strlen(path1); i>0; i--)
  52.     {
  53.         if (path1[i] == '/')
  54.  
  55.         {
  56.             j = i; break;
  57.         }
  58.     }
  59.     l = j;
  60.  
  61.     //cout << extension<<endl; // беру всё что после . стоит с помощью отмеченой j
  62.  
  63.  
  64.     if (l != 0){
  65.         strncpy_s(path, path1, j + 1);
  66.     }
  67.     //cout << path <<endl;
  68.  
  69.     string b = path1;
  70.     if (j != 0){
  71.         b.erase(0, j + 1);
  72.     }
  73.     char * name = (char*)b.c_str();
  74.  
  75.     j = 0;
  76.    
  77.     for (i = 0; i<strlen(path); i++)
  78.     {
  79.         if (path[i] == '/') { break; }
  80.         if (path[i] == '.') { j = i; break; }
  81.     }
  82.     if ((j = 0) || (strlen(name) == 0))
  83.  
  84.     {
  85.         strncpy_s(name1, path, j);
  86.     }
  87.  
  88.    
  89.     char * extension = (char*)g.c_str();
  90.     SplitFilename(str, path, name, extension);
  91.    
  92.  
  93.     system("pause");
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement