· 5 years ago · Apr 29, 2020, 06:26 PM
1#include <stdio.h>
2#include <stdlib.h>
3#include <direct.h>
4#include <string.h>
5#include <errno.h>
6#include <io.h>
7#include <time.h>
8
9void Pause()
10{
11 char choice;
12
13 while (1)
14 {
15 printf("\nInput Q to quit: ");
16 scanf("%c", &choice);
17 if (choice == 'q' || choice == 'Q')
18 {
19 exit(0);
20 break;
21 }
22 else
23 {
24 printf("\nWrong input try again\n");
25 }
26 }
27 return;
28}
29int partRemover(char filename[])
30
31{
32 FILE *f1, *f2;
33 snprintf(filename, 64, "%s", filename);
34 f2 = fopen(filename, "r");
35
36 if (f2 == NULL)
37 {
38
39 return -1;
40 }
41 f1 = fopen("edited.txt", "w");
42 if (f1 == NULL)
43 {
44 return -1;
45 }
46
47 do
48 {
49
50 char str[200];
51 fgets(str, 200, f2);
52 if (feof(f2))
53 {
54 break;
55 }
56 int i = 0;
57 while (str[i] != '|')
58 {
59
60 fputc(str[i], f1);
61 i++;
62 }
63 fputc('\n', f1);
64
65 } while (1);
66
67 fclose(f1);
68 fclose(f2);
69 return 1;
70}
71int main()
72{
73 time_t now;
74 char timeNow[26];
75 time(&now);
76 strcpy(timeNow, ctime(&now));
77 printf("Time: %s\n\n", timeNow);
78
79 char flnm[64], flnm1[64];
80
81 printf("Write Relative/Absolute path of main list (include extension): ");
82 scanf("%s", flnm);
83 if (partRemover(flnm) == -1)
84 {
85 printf("There is no such file on this PC/You inputed incorrect path\n");
86
87 Pause();
88 }
89 printf("Input the name of results filename (include extension): ");
90 scanf("%s", flnm1);
91
92 char c, results[100] = "Results", timeNow1[31];
93 strncpy(timeNow1, ctime(&now),26);
94 timeNow1[25]='\0';
95 char ch1[1] = "[";
96 strncat(results, ch1, 1);
97 char ch2[1] = "]";
98 strcat(results, timeNow1);
99 strncat(results, ch2, 1);
100 snprintf(results, 100, "%s", results);
101 int check = _mkdir(results);
102
103 if (check == -1)
104 {
105 if (errno == ENOENT)
106 {
107 printf("Path not found");
108 Pause();
109 }
110
111 else
112 {
113 printf("Unknown error");
114 Pause();
115 }
116 }
117
118 FILE *fp, *fn;
119 char ch3[1] = "\\";
120 strncat(results, ch3, 1);
121 strcat(results, flnm1);
122 fp = fopen("edited.txt", "r");
123 if (fp == NULL)
124 {
125 printf("Error in load of file");
126 Pause();
127
128 return 0;
129 }
130 snprintf(results, 72, "%s", results);
131 fn = fopen(results, "w");
132
133 if (fn == NULL)
134 {
135 printf("Error in load of file");
136 Pause();
137 return 0;
138 }
139
140 do
141 {
142
143 c = fgetc(fp);
144 if (feof(fp))
145 {
146 break;
147 }
148 if (c == '@')
149 {
150 fputc(c, fn);
151 c = fgetc(fp);
152 if (c == 'g')
153 {
154
155 fprintf(fn, "yahoo");
156 fseek(fp, 4, SEEK_CUR);
157 }
158 else if (c == 'y')
159 {
160 fprintf(fn, "gmail");
161 fseek(fp, 4, SEEK_CUR);
162 }
163 else if (c == 'h')
164 {
165 fprintf(fn, "gmail");
166 fseek(fp, 6, SEEK_CUR);
167 }
168 else if (c == 'i')
169 {
170 fprintf(fn, "gmail.com");
171 fseek(fp, 9, SEEK_CUR);
172 }
173 else if (c == 'o')
174 {
175 fprintf(fn, "gmail.com");
176 fseek(fp, 5, SEEK_CUR);
177 }
178 }
179
180 else
181 {
182 fputc(c, fn);
183 }
184 }
185
186 while (1);
187 fclose(fn);
188 fclose(fp);
189 remove("C:\\OGNJEN\\Programming\\C\\Projects\\CombolistEditorSimple\\edited.txt");
190 printf("\nSuccesfull\n");
191 return 1;
192}