-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadMeGenerator.c
161 lines (128 loc) · 4.97 KB
/
ReadMeGenerator.c
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
int main() {
//Ask the user to determine a name for their file
char fileName[36] = { 0 };
printf("%s", "Please enter a name for your file, must be under 32 characters(Recommended: README): \n");
fgets(fileName, 32, stdin);
//Remove new line character
for (int i = 0; i < 32; i++){
if (fileName[i] == 10){
fileName[i] = 0;
}
}
//Add file extension
strcat(fileName, ".txt");
//Open file to write to
FILE* README;
README = fopen(fileName, "w+");
char currentPrompt[10001] = { 0 };
int inputSize = 1;
//Ask user for project name
printf("%s", "\n\nPlease follow the prompts to complete your README file. All inputs will only accept up to 10000 characters. \n\n");
printf("%s", "Project Name: \n\n");
fgets(currentPrompt, 10000, stdin);
//Get total input size
for (int i = 0; i < 10000; i++){
if (currentPrompt[i] != 10){
inputSize += 1;
}else {
break;
}
}
//Write project name
fwrite("Project Name: ", 1, 24, README);
fwrite(currentPrompt, 1, inputSize, README);
fputc('\n', README);
//Add spacer
fwrite("____________________________________________________________________________________________________\n", 1, 101, README);
//Ask user for project description
printf("%s", "\nProject Description: \n\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
//Get total input size
inputSize = 1;
for (int i = 0; i < 10000; i++){
if (currentPrompt[i] != 10){
inputSize += 1;
}else {;
break;
}
}
//Write project description
fwrite("Project Description: ", 1, 24, README);
int totalPrinted = 0;
while (totalPrinted < inputSize){
fputc(currentPrompt[totalPrinted], README);
//Check if a space is starting the current line
if (totalPrinted % 50 == 0 && currentPrompt[totalPrinted] == ' ' && totalPrinted >= 50){
totalPrinted += 1;
fputc('\n', README);
fwrite(" ", 1, 24, README);
continue;
}
//Check if a dash to show to complete a word
if (currentPrompt[totalPrinted] != ' ' && currentPrompt[totalPrinted - 1] != ' ' && totalPrinted % 50 == 0 && totalPrinted >= 50){
fputc('-', README);
fputc('\n', README);
fwrite(" ", 1, 24, README);
}else if (totalPrinted % 50 == 0 && totalPrinted >= 50){
fputc('\n', README);
fwrite(" ", 1, 24, README);
}
totalPrinted += 1;
}
fputc('\n', README);
//Add spacer
fwrite("____________________________________________________________________________________________________\n", 1, 101, README);
//Ask user for all dependencies
printf("%s", "\nNumber of Project Dependencies: \n\n");
int numberofDependencies;
fgets(currentPrompt, 10000, stdin);
sscanf(currentPrompt, "%d", &numberofDependencies);
fwrite("Dependencies:\n\n", 1, 15, README);
//Loop through for each dependency
for (int i = 0; i < numberofDependencies; i++){
//Dependency Name
printf("%s%d%s", "Dependency Name(", i, "):\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
fwrite("--------------------------------------------------\n", 1, 51, README);
fwrite(" Dependency Name: ", 1, 24, README);
fputs(currentPrompt, README);
fputs("\n\n", README);
//Dependency Author
printf("%s%d%s", "Dependency Author(", i, "):\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
fwrite(" Dependency Author: ", 1, 24, README);
fputs(currentPrompt, README);
fputs("\n\n", README);
//Dependency Version
printf("%s%d%s", "Dependency Version(", i, "):\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
fwrite(" Dependency Version: ", 1, 24, README);
fputs(currentPrompt, README);
fputs("\n\n", README);
//Dependency Date Accessed
printf("%s%d%s", "Date Accessed(", i, "):\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
fwrite(" Date Accessed: ", 1, 24, README);
fputs(currentPrompt, README);
fputs("\n\n", README);
//Source Location
printf("%s%d%s", "Source Location(", i, "):\n");
memset(currentPrompt, 0, 10000);
fgets(currentPrompt, 10000, stdin);
fwrite(" Source Location: ", 1, 24, README);
fputs(currentPrompt, README);
fwrite("--------------------------------------------------\n", 1, 51, README);
}
//Close the file
fclose(README);
return 0;
}