Got rid of some useless functions and commented all the code

This commit is contained in:
Ricardo
2022-05-30 19:52:15 +00:00
parent 8a1ae2ca1a
commit 90a67543f0
4 changed files with 50 additions and 56 deletions

49
main.c
View File

@@ -12,11 +12,11 @@
// Necessary to initalize my struct with all the info
struct parameters info = {
.filename = "EMPTY",
.fd = NULL,
.version = "1.0",
.fileNameSize = 80,
// Below is the variable that olds the text to dislpay for help
.filename = "EMPTY", // Here we store the file name
.fd = NULL, // File descriptor
.version = "1.0", // Software version
.fileNameSize = 80, // How many characters has the filename, including extention
// Below is the variable that holds the text to dislpay for help
.help = "\n\
------------------------------------------------\n\
Usage: ./inverT -i [<some.text.file>]\n\
@@ -30,35 +30,38 @@ Example: ./inverT -i test.txt\n",
int main (int argc, char *argv[]) {
if (argc == 1) {
ask_file();
if (argc == 1) { // If only one argument
ask_file(); // Ask user for the file name and location
invert_file(); // and invert the file content
}
else if (argc == 2) {
if (strncmp(argv[1], "-help", 5) == 0) {
printf("%s\n", info.help);
else if (argc == 2) { // If two arguments
if (strncmp(argv[1], "-help", 5) == 0) { // Check if the flag is '-help'
printf("%s\n", info.help); // and print help info
}
else if (strncmp(argv[1], "-v", 2) == 0) {
printf("Version %s\n", info.version);
else if (strncmp(argv[1], "-v", 2) == 0) { // Check if the flag is '-v'
printf("Version %s\n", info.version); // and print version info
}
else {
get_file(argv[1]);
else { // Otherwise
strcpy(info.filename, argv[1]); // save the second argument into info.filename
invert_file(); // and invert the file content
}
}
else if (argc == 3) {
if(strncmp(argv[1], "-i", 2) == 0) {
get_file(argv[2]);
else if (argc == 3) { // If three arguments
if(strncmp(argv[1], "-i", 2) == 0) { // Check if the flag is '-i'
strcpy(info.filename, argv[2]); // save the third argument into info.filename
invert_file(); // and invert the file content
}
else {
printf("\nInvalid flag!!!");
printf("%s\n", info.help);
else { // Otherwise
printf("\nInvalid flag!!!"); // print this
printf("%s\n", info.help); // and then print help info
}
}
else {
printf("\nTo many arguments!!!");
printf("%s\n", info.help);
else { // Otherwise if more then three arguments
printf("\nTo many arguments!!!"); // print this
printf("%s\n", info.help); // and then print help info
}
return 0;