-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.cpp
More file actions
96 lines (70 loc) · 1.77 KB
/
Copy pathsource.cpp
File metadata and controls
96 lines (70 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
void open(ifstream &file,string path){
file.open(path);
if(!file.is_open()) cout << "loading database error\n";
}
void open(fstream &file,string path){
file.open(path);
if(!file.is_open()) cout << "loading database error\n";
}
void close(ifstream &file){
file.close();
}
void close(fstream &file){
file.close();
}
string askname(){
string name;
cout << "Give File Path :\n";
cin >> name;
return name;
}
int linesize(){
int ls;
cout << "give line size : ";
cin >> ls;
return ls;
}
void modify(string inputpath, string outputpath, int linesize){
ifstream file;
fstream out ;
out.open(outputpath,std::ios::out);
open(file, inputpath);
int count = 0;
char ch;
string word;
string line = "";
cout << "\n\nGenerating output file....\n";
while(file.get(ch)){
word = ch;
while (!isspace((int)ch)){
file.get(ch);
word = word+ch;
}
int temp = file.peek();
if (word.length()+line.length() > linesize || temp == EOF ){
out << line << '\n';
count++;
line = word;
}
else {
line = line + word + ' ';
}
}
close(out);
close(file);
cout << "\n\nProcess Complete.\n";
cout << count <<" lines added.\n";
}
int main(){
cout << "#### LINE FORMAT #### \n";
int size = linesize();
cout << "#### INPUT FILE #### \n";
string in = askname();
cout << "#### OUTPUT FILE #### \n";
string out = askname();
modify(in,out,size);
}