Repository navigation
Expand file tree
/
Copy pathreport.c
More file actions
59 lines (47 loc) · 1.48 KB
/
Copy pathreport.c
File metadata and controls
59 lines (47 loc) · 1.48 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
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
extern char *targetString;
extern char *filesChanged;
extern int numOfFilesChanged;
//function for qsort
int compareStr(const void *pa, const void *pb) {
const char* aa = *(const char**)pa;
const char* bb = *(const char**)pb;
//return the inverse of strncmp to get inverse order (most edits first)
return strncmp(aa,bb, 1)*(-1);
}
void createReport() {
//initialize an area for the files changed
char *files[numOfFilesChanged];
//splitting filesChanged char array to 2d char array
if (numOfFilesChanged>0) {
char* token;
token = strtok(filesChanged, "\n");
int i = 0;
while (token != NULL) {
files[i++] = token;
token = strtok(NULL, "\n");
}
//sort files array
int m = sizeof(files)/numOfFilesChanged;
qsort(files, numOfFilesChanged, m, compareStr);
}
//print target string
printf("Target string: %s\n\n", targetString);
//getting current directory
char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
perror("Error: could not get current directory.\n");
}
else {
printf("Search begins in current folder: %s\n\n\n", cwd);
}
//printing search report
printf("*** Search Report ***\n\n");
printf("Updates\t\tFile Name\n");
//print sorted files
for (int i = 0; i < numOfFilesChanged; i++) printf("%s\n", files[i]);
return;
}