Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Good day everyone!..
im having difficulty to merge this two program..in this code the data in the text file are tokenize it has the delimiter ","..


C++
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
string str = "ako reiku xian"; 
size_t length;
char buffer[str.length()];
length=str.copy(buffer,str.length(),0);
buffer[length]='\0';
char *pch = buffer;

pch = strtok (pch," ");
while (pch != NULL)
{
cout<<pch<<",";
pch = strtok (NULL, " ");
}

//system("pause");
getch();
}



-------------------------------
in this code the program show only the folder name that is being saved in the text file but its not yet being tokenize w/ the delemiter of ","

C++
#include<iostream>
#include <fstream>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

using namespace std;

int main()
{
    ifstream fin;
    string dir, filepath, username, password;
    int num;
    DIR *dp;
    struct dirent *dirp;
    struct stat filestat;


    dir = "C:\\Users\\ROAN\\Desktop\\folder";

    cout<<"Enter username: ";
    getline( cin, username );
    cout<<"Enter password: ";
    getline( cin, password );

    dp = opendir( dir.c_str() );
    while ((dirp = readdir( dp )))
    {
          string un, pw, folder;
          filepath = dir + "/" + dirp->d_name;

          if (stat( filepath.c_str(), &filestat )) continue;
             if (S_ISDIR( filestat.st_mode ))      continue;

          fin.open( filepath.c_str() );

          if (getline( fin, un ) && getline( fin, pw ))
             if (un == username && pw == password)
             {
                getline(fin, folder);
                cout << folder << endl;

                //open folder
                /*C:\Users\ROAN\Desktop\folder*/
              //   system("start explorer C:\\Users\\ROAN\\Desktop\\folder\\");

              //  mkdir(dir);
             }

          fin.close();
    }

  closedir( dp );
  system("pause");
  return 0;

}
Posted
Updated 22-Feb-12 19:40pm
v3
Comments
Sergey Alexandrovich Kryukov 23-Feb-12 3:37am    
Not a valid question.

"Merge these programs" is not an ultimate goal, right? The goal is to write some code. So, please explain what this code should do? What's the problem? Forget about the merge.

--SA
reikuxian 23-Feb-12 9:24am    
sample in the .txt file there must be a data that has a username password and the folder name its must save with a comma that separator...example: reiku,xian,roan ...it must supposed to be like this in a text file..in my program it save in like this
reiku
xian
roan ...
Legor 23-Feb-12 9:05am    
What do you mean by merge this code?
reikuxian 23-Feb-12 10:46am    
sample in the .txt file there must be a data that has a username password and the folder name its must save with a comma that separator...example: reiku,xian,roan ...it must supposed to be like this in a text file..in my program it save in like this
reiku
xian
roan ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900