-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenFile.cpp
More file actions
109 lines (95 loc) · 2.41 KB
/
openFile.cpp
File metadata and controls
109 lines (95 loc) · 2.41 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
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <cstring>
#include "kelolaText.h"
#include "findReplace.h"
#include <windows.h>
#include <conio.h>
#include "saveToFIle.h"
//void openFile(){
// char choice;
// system("cls");
// char *fileName;
//
// printf("Enter file name: ");
// fileName=(char*) malloc(20* sizeof(char));
// scanf("%s", fileName);
//
// FILE *file = fopen(fileName, "r");
// if (!file) {
// printf("File not found!\n");
// printf("Press enter to go back ...");
// getch();
// openFile();
// } else {
// char text[100];
// while (fgets(text, 100, file) != NULL) {
// printf("%s", text);
// }
// fclose(file);
// }
// printf("Do you want to edit the text? (y/n)\n");
// getch();
// choice = getche();
// if(choice == 'y'){
// findReplace(fileName);
// getch();
// }else{
// printf("\nWrong Input!");
// }
//}
void printFromFile(char path[50]){
char text[80];
FILE *read = fopen(path, "r");
while (fgets(text, 80, read) != NULL) {
printf("%s", text);
}
fclose(read);
}
// open file and print to array 2 dimensi
void openFileTwoDimensi(){
char choice;
system("cls");
char *fileName;
char text[MAXBARIS][MAXKOLOMARR];
setArr(text);
printf("TitorApps\n");
printf("Enter file name: ");
fileName=(char*) malloc(20* sizeof(char));
scanf("%s", fileName);
FILE *file = fopen(fileName, "r");
if (!file) {
printf("File not found!\n");
printf("Press enter to go back ...");
getch();
// openFile();
} else {
system("cls");
int i = 0;
int jmlBaris;
while (fgets(text[i], MAXKOLOMARR, file) != NULL) {
i++;
}
fclose(file);
print2DArr(text, 0, i);
// insert mode
jmlBaris = insertMode(text, i);
// update file fileName
while (1)
{
printf("Do you want to update the file? (y/n) : ");
choice = getch();
if (choice == 'y')
{
updateFile(fileName, jmlBaris, text);
break;
} else if (choice == 'n') {
printf("\nYour file is not updated!");
getch();
break;
} else {
printf("\n");
printf("Wrong Input!\n");
}
}
}
}