Code:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;
// Function protos
void init_array(char ascii[63], char myb[64]);
// !! Function protos
int main()
{
//declaration & init
char ascii[63];
char myb[64];
char *filename_p;
filename_p=new char [300];
int a=48;
int b=0;
int count_filename=0;
int count_orig=0;
int chck_name=0;
ifstream in_orig;
ofstream test; // for Testing
// !! Declaration
// Input fiile name and open
test.open("test.txt");
init_array(ascii,myb);
test << ascii;
do
{
cout << "Enter a file name or complete path(if outside the current folder) or 0 to exit:" << endl;
cin.getline(filename_p,300);
in_orig.open(filename_p);
if (*filename_p == '0')
{
exit(1);
}
else if (in_orig.fail())
{
cout << "File doesnot exist at the current location."<< endl;
}
else if (((*filename_p).find(".txt")) != string::npos)
{
chck_name=1;
}
}
while ((in_orig.fail()) && chck_name);
// !! filename and open
//Counting no of char in filename
a=0;
cin.ignore(120,'\n');
while (filename_p[a]!='\0')
{
count_filename++ ;
cout<< a << endl;
a++;
}
cout << count_filename;
// !Counting no of char in filename
return 0;
}
// Functions to Initialize arrays
void init_array(char ascii[63], char myb[64])
{
// ofstream test1;
//test1.open("test1.txt");
int a=48;
int b=0;
/* storing values in ascii, i.e
={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, }*/
a=48;
while (a < 123)
{
if (((a >= 48) && (a < 58)) || ((a >= 65) && (a <= 90)) || ((a >= 97) && (a <= 122)))
{
ascii[b]=a;
b++;
}
if ( b==63)
{
ascii[b]=32;
}
a++;
}
// !! Stored in ascii
//cout << ascii << endl;
a=0;
while (a < 63)
{
myb[a]=char(a);
/*char c;
c=myb[a]| (char)65;
//test1 << a << " " << (int)myb[a] << endl;*/
(int)a++;
}
/*char c=myb[1];
c = c << 6;
c= c| char(1);
test1 << c << endl;
*/
}