From 74c2edd862aa775e6159508b6f3abb322c7a1a4a Mon Sep 17 00:00:00 2001 From: Shreejan Date: Wed, 24 Nov 2021 22:20:44 +0530 Subject: [PATCH] Refined some of the bugs of gets() and freed the memory --- CommandConsole.exe | Bin 52342 -> 53367 bytes calc_file.h => calc_file.c | 132 ++++++++++++------------- ccwd_file.c | 21 ++++ ccwd_file.h | 16 --- change_dir_path.h => change_dir_path.c | 6 +- change_root.h => change_root.c | 50 +++++----- clr_file.h => clr_file.c | 28 +++--- copy_file.c | 44 +++++++++ copy_file.h | 32 ------ date_file.h => date_file.c | 22 ++--- echo_file.h => echo_file.c | 6 +- file_mkdr1.h => file_mkdr1.c | 50 +++++----- help_file.h => help_file.c | 56 +++++------ list_file.h => list_file.c | 49 +++++---- main.c | 61 ++++++------ make_file.h => make_file.c | 29 +++--- open_file1.c | 35 +++++++ open_file1.h | 31 ------ pcwd_file.h => pcwd_file.c | 47 +++++---- remo_file.c | 20 ++++ remo_file.h | 12 --- rename_file.h => rename_file.c | 11 ++- rmdr_file.h => rmdr_file.c | 52 +++++----- system_info.h => system_info.c | 0 userinfo.h => userinfo.c | 0 wrta_file.c | 31 ++++++ wrta_file.h | 19 ---- wrte_file.c | 32 ++++++ wrte_file.h | 21 ---- 29 files changed, 485 insertions(+), 428 deletions(-) rename calc_file.h => calc_file.c (95%) create mode 100644 ccwd_file.c delete mode 100644 ccwd_file.h rename change_dir_path.h => change_dir_path.c (97%) rename change_root.h => change_root.c (75%) rename clr_file.h => clr_file.c (95%) create mode 100644 copy_file.c delete mode 100644 copy_file.h rename date_file.h => date_file.c (95%) rename echo_file.h => echo_file.c (62%) rename file_mkdr1.h => file_mkdr1.c (81%) rename help_file.h => help_file.c (98%) rename list_file.h => list_file.c (89%) rename make_file.h => make_file.c (64%) create mode 100644 open_file1.c delete mode 100644 open_file1.h rename pcwd_file.h => pcwd_file.c (89%) create mode 100644 remo_file.c delete mode 100644 remo_file.h rename rename_file.h => rename_file.c (58%) rename rmdr_file.h => rmdr_file.c (81%) rename system_info.h => system_info.c (100%) rename userinfo.h => userinfo.c (100%) create mode 100644 wrta_file.c delete mode 100644 wrta_file.h create mode 100644 wrte_file.c delete mode 100644 wrte_file.h diff --git a/CommandConsole.exe b/CommandConsole.exe index 80c6723f4de4e113a2b6efe31cb43272fd8833ff..3279bd0926afd77ff930e218e80e8f1c162c21c4 100644 GIT binary patch delta 10221 zcmaJ{30PFu*}nHO2nw<&?g#@?_aIhOjDQnikTgd5TNgCwfGmOzOJS(`S2Lza10n`J zF(Gk@CN9*t;gD2~u{2nhBuz}3KQYx>nwsPiNW-5RHA^#nzjL>_O_O;ZX1?=&@3)@i z-aEtXX1_ao{hI2A|IN84PiPi|`y@f=6avH`QHm67f*_P_dv=;sabw$`5B77-!Z-|n zHnv%uFfJXE&&wtxw8vK#K5dUk1A&juEq2A8Ec=#1=_o#4`3U-YeKa zyjQX}@a|%_@xGl!`Hc}DXBl{Zf|dDQkcv~-G|SJVfhnxPGIhlDWI?F8D^~yUVtSlK zgzJlzxIlc!9m(vPB|+Mj%=-Ihgxn7rG*Afg$XJ%=A1OsAGq?Y6$uF7h^dBi+WvBfo zM0S$59*dkiOc3@3X4!;#OPpL21EXVuw)cs-{{iUtS(|_(T0>d_si&KJYd+L2fSr><-50 zO&Xm^Vs8bGaQnkwy}g$b{6E0Zc9HfU+(A!+y_bUaVpM0p1LfDGTt|+Ehn}wMfIQfyXtuXWImXS6IdO|Z+_>R3j6v^5i!1`Gd+Oz0FS(x#wK_t5@EJiVyfj_&S<~Yl3v>vf z89>ppQ?&SbK$_52fFQ&Xp%$_!)-XPyf1*H_p=-2ru@6LLLjS}eC2%HrNc*mb60$o( zE*|ABxOje==Hd)rnlv%0_a$Iqx@tD`Diix8`MnN)_iCEL=P*?LP2x;#1}9Hv%li#> ze+i~KS0T`AbM-!XR}wuy4mWcepOw!Hi<=OYxv1$$x@fr>>Q!6uDIAe|j_|6l0nyez7diSNM6Cfs5h;?A%>oFyg5-2XUY`#+ zN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c0FU?z4n32x~=tzOQkhvN{-ecjt=aJ6JFDlL9 znhcyIaHbiuoD0NcK(c_~Um-o``#PXHL*fU4L~CaDrKLGJE3nlK!A^qHZ9vWgq5qQW zm23logT>)+E7ks0;yA56NFG3RE6~mQVt;PY!b8OkqaBM&=R6Grr&MwaDz5oJ=wVkm zAQ_oOCAf#T8dA)X{jk5C9PV5NIZoq~he{x#VNJIKS!Lkt0}>9d8k^&e0-0yvoCUI8 z^CKN7Jk8wD`U1te>I7*V1awqP!oJjzlb;VWL%P3!lVVtzet7z^XjTxoP#{T$@KHeM zpR)Q{c@Bttg>wQQ43Xzp*Qo$!E)-z)sB48n)hoRTNCh}@q7b+@fz%m79sr^qDJXCq z2hwJk%*R0JnLtnLk`vHu19SsOom41w$8-RpOE-H6#MrL`@GSScVaB0A=+dVV4`hRZ z^GrWF2L@6ONcCDm_EJYlKDz8Zt$`A|44iugN7X>^pwpv5dk8Ts++iTbe(|?{IEOP0 zqz;hir=>nu0gpjPG{jz9l2_|g}-|bly35NdtN~??qDlR^6*Iif9z}(V*mgE diff --git a/calc_file.h b/calc_file.c similarity index 95% rename from calc_file.h rename to calc_file.c index 37134f5..626bb13 100644 --- a/calc_file.h +++ b/calc_file.c @@ -1,67 +1,67 @@ -#include -#include - -void calc() -{ - char type; - printf("Enter d for decimal operations and i for integer operation: "); - scanf("%c", &type); - if (type == 'i') - { - getchar(); - int a, b; - printf("Enter first number: "); - scanf("%d", &a); - printf("Enter second number: "); - scanf("%d", &b); - char o; - printf("Enter operation(+, -, /, *): "); - getchar(); - scanf("%c", &o); - if (o == '+') - { - printf("%d\n\n", a + b); - } - else if (o == '-') - { - printf("%d\n\n", a - b); - } - else if (o == '*') - { - printf("%d\n\n", a * b); - } - else if (o == '/') - { - printf("%d\n\n", a / b); - } - } - else - { - getchar(); - float x, y; - printf("Enter first number: "); - scanf("%f", &x); - printf("Enter second number: "); - scanf("%f", &y); - char o; - printf("Enter operation(+, -, /, *): "); - getchar(); - scanf("%c", &o); - if (o == '+') - { - printf("%.2f\n\n", x + y); - } - else if (o == '-') - { - printf("%.2f\n\n", x - y); - } - else if (o == '*') - { - printf("%.2f\n\n", x * y); - } - else if (o == '/') - { - printf("%.2f\n\n", x / y); - } - } +#include +#include + +void calc() +{ + char type; + printf("Enter d for decimal operations and i for integer operation: "); + scanf("%c", &type); + if (type == 'i') + { + getchar(); + int a, b; + printf("Enter first number: "); + scanf("%d", &a); + printf("Enter second number: "); + scanf("%d", &b); + char o; + printf("Enter operation(+, -, /, *): "); + getchar(); + scanf("%c", &o); + if (o == '+') + { + printf("%d\n\n", a + b); + } + else if (o == '-') + { + printf("%d\n\n", a - b); + } + else if (o == '*') + { + printf("%d\n\n", a * b); + } + else if (o == '/') + { + printf("%d\n\n", a / b); + } + } + else + { + getchar(); + float x, y; + printf("Enter first number: "); + scanf("%f", &x); + printf("Enter second number: "); + scanf("%f", &y); + char o; + printf("Enter operation(+, -, /, *): "); + getchar(); + scanf("%c", &o); + if (o == '+') + { + printf("%.2f\n\n", x + y); + } + else if (o == '-') + { + printf("%.2f\n\n", x - y); + } + else if (o == '*') + { + printf("%.2f\n\n", x * y); + } + else if (o == '/') + { + printf("%.2f\n\n", x / y); + } + } } \ No newline at end of file diff --git a/ccwd_file.c b/ccwd_file.c new file mode 100644 index 0000000..4018922 --- /dev/null +++ b/ccwd_file.c @@ -0,0 +1,21 @@ +#include +#include +#include "change_dir_path.c" //including the change_dir_path.h to get the variable change_dir. +#include +#include + +void ccwd() +{ + printf("Enter the path to change this directory to: \n"); + getchar(); + fgets(change_dir, 100, stdin); + change_dir[strlen(change_dir) - 1] = 0; + if (chdir(change_dir) == 0) //implementing chdir function. + { + printf("successfully changed\n"); + } + else + { + printf("Cannot change the directory.\n"); + } +} \ No newline at end of file diff --git a/ccwd_file.h b/ccwd_file.h deleted file mode 100644 index ce918d3..0000000 --- a/ccwd_file.h +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include "change_dir_path.h"//including the change_dir_path.h to get the variable change_dir. -#include -#include - -void ccwd() -{ - printf("Enter the path to change this directory to: \n"); - getchar(); - gets(change_dir); - if (chdir(change_dir) == 0)//implementing chdir function. - { - printf("successfully changed\n"); - } -} \ No newline at end of file diff --git a/change_dir_path.h b/change_dir_path.c similarity index 97% rename from change_dir_path.h rename to change_dir_path.c index a95d09a..8f8ed62 100644 --- a/change_dir_path.h +++ b/change_dir_path.c @@ -1,4 +1,4 @@ -#include -#include - +#include +#include + char change_dir[100];//assigning at least 100 characters to the new directory name entered by user. \ No newline at end of file diff --git a/change_root.h b/change_root.c similarity index 75% rename from change_root.h rename to change_root.c index 88f547b..b912f44 100644 --- a/change_root.h +++ b/change_root.c @@ -1,24 +1,28 @@ -#include -#include - - -//function to change the username and password -void change(){ - char username_new[10], password_new[10]; - int i =0; - getchar(); - printf("Now you can change the username and password.\n"); - printf("Enter new username-"); - gets(username_new);//new username - printf("Enter new password-"); - gets(password_new);//new password - FILE *new_user; - FILE *new_password; - //writing in the files the new username and password - new_user = fopen("root_username.txt", "w"); - new_password = fopen("password_root.txt", "w"); - fprintf(new_user, username_new); - fprintf(new_password, password_new); - fclose(new_user); - fclose(new_password); +#include +#include + + +//function to change the username and password +void change(){ + char username_new[10], password_new[10]; + int i =0; + getchar(); + printf("Now you can change the username and password.\n"); + printf("Enter new username-"); + fgets(username_new, 10, stdin);//new username + username_new[strlen(username_new) - 1] = 0; + + printf("Enter new password-"); + fgets(password_new, 10, stdin);//new password + password_new[strlen(password_new) - 1] = 0; + + FILE *new_user; + FILE *new_password; + //writing in the files the new username and password + new_user = fopen("root_username.txt", "w"); + new_password = fopen("password_root.txt", "w"); + fprintf(new_user, username_new); + fprintf(new_password, password_new); + fclose(new_user); + fclose(new_password); } \ No newline at end of file diff --git a/clr_file.h b/clr_file.c similarity index 95% rename from clr_file.h rename to clr_file.c index deccb7f..02fa204 100644 --- a/clr_file.h +++ b/clr_file.c @@ -1,14 +1,14 @@ -#include -#include - -//I have made this function thinking that the clearScreen will work on every system. -void clearScreen() -{ -#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) - system("clear"); -#endif - -#if defined(_WIN32) || defined(_WIN64) - system("cls"); -#endif -} +#include +#include + +//I have made this function thinking that the clearScreen will work on every system. +void clearScreen() +{ +#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) + system("clear"); +#endif + +#if defined(_WIN32) || defined(_WIN64) + system("cls"); +#endif +} diff --git a/copy_file.c b/copy_file.c new file mode 100644 index 0000000..7c14f42 --- /dev/null +++ b/copy_file.c @@ -0,0 +1,44 @@ +#include +#include +#include + +// Fucntion to copy file +void copy() +{ + FILE *ptr1; + FILE *ptr2; + char filename1[25], filename2[25], content; + + getchar(); + printf("Enter the filename to be copied- "); + fgets(filename1, 25, stdin); + filename1[strlen(filename1) - 1] = 0; + + printf("Now enter the name of the file in which the contents of the %s to be copied - ", filename1); + fgets(filename2, 25, stdin); + filename2[strlen(filename2) - 1] = 0; + + ptr1 = fopen(filename1, "r"); + + if (ptr1 == NULL) + { + printf("Cannot copy\n"); + } + else + { + ptr2 = fopen(filename2, "w"); + + content = fgetc(ptr1); + + while (content != EOF) + { + fputc(content, ptr2); + content = fgetc(ptr1); + } + + printf("\nSuccessfully copied to %s \n", filename1); + fclose(ptr2); + } + + fclose(ptr1); +} \ No newline at end of file diff --git a/copy_file.h b/copy_file.h deleted file mode 100644 index fb8918f..0000000 --- a/copy_file.h +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -// Fucntion to copy file -void copy() -{ - FILE *ptr1; - FILE *ptr2; - char filename1[100], filename2[100], content; - - getchar(); - printf("Enter the filename to be copied- "); - gets(filename1); - printf("Now enter the name of the file in which the contents of the %s to be copied - ", filename1); - gets(filename2); - - ptr1 = fopen(filename1, "r"); - ptr2 = fopen(filename2, "w"); - content = fgetc(ptr1); - - while (content != EOF) - { - fputc(content, ptr2); - content = fgetc(ptr1); - } - - printf("\nSuccessfully copied to %s \n", filename1); - - fclose(ptr1); - fclose(ptr2); -} \ No newline at end of file diff --git a/date_file.h b/date_file.c similarity index 95% rename from date_file.h rename to date_file.c index da7abd0..8e873b2 100644 --- a/date_file.h +++ b/date_file.c @@ -1,12 +1,12 @@ -#include -#include -#include - - -//date function. If the user clears the screen it can be usefule to see the date. -void date() -{ - time_t t; - time(&t); - printf("%s\n\n", ctime(&t)); +#include +#include +#include + + +//date function. If the user clears the screen it can be usefule to see the date. +void date() +{ + time_t t; + time(&t); + printf("%s\n\n", ctime(&t)); } \ No newline at end of file diff --git a/echo_file.h b/echo_file.c similarity index 62% rename from echo_file.h rename to echo_file.c index 8fe71b6..996534e 100644 --- a/echo_file.h +++ b/echo_file.c @@ -4,8 +4,8 @@ //Function to print the anything which user has given. void echo() { - getchar(); + fgetc(stdin); char user_str[1000000]; - gets(user_str); - puts(user_str); + fgets(user_str, 1000000, stdin); + printf("%s", user_str); } \ No newline at end of file diff --git a/file_mkdr1.h b/file_mkdr1.c similarity index 81% rename from file_mkdr1.h rename to file_mkdr1.c index e1301d2..833cb4f 100644 --- a/file_mkdr1.h +++ b/file_mkdr1.c @@ -1,26 +1,26 @@ -#include -#include "change_dir_path.h" -#include -#include -#include -#define SIZE 25 - -//function to make a folder. -void mkdr() -{ - int check; - char *dirname; - dirname = malloc(SIZE * sizeof(char)); - printf("Enter a name of the folder:"); - getchar(); - gets(dirname); - check = mkdir(dirname); - - if (!check) - printf("Directory created\n"); - - else - { - printf("Unable to create directory\n"); - } +#include +#include "change_dir_path.c" +#include +#include +#include +#define SIZE 25 + +//function to make a folder. +void mkdr() +{ + int check; + char *dirname; + dirname = malloc(SIZE * sizeof(char)); + printf("Enter a name of the folder:"); + getchar(); + fgets(dirname, 25, stdin); + dirname[strlen(dirname) - 1] = 0; + check = mkdir(dirname); + if (!check) + printf("Directory created\n"); + + else + { + printf("Unable to create directory\n"); + } } \ No newline at end of file diff --git a/help_file.h b/help_file.c similarity index 98% rename from help_file.h rename to help_file.c index 9896645..4fc9330 100644 --- a/help_file.h +++ b/help_file.c @@ -1,29 +1,29 @@ -#include - -//function to print the help menu. -void help() -{ - printf("\tIn all the cases first write the command hit enter and then give the arguements\n\n"); - - printf(">>calc - This command open a terminal calculator and you can do simple calculator operation in this.\n\tThe operaation are - (+, -, * , /, ^(Power of. Ex- 3^2 = 9)\n\tFirst number (operation) Second Number\n\tFor doing operation in decimal give d and for integer give i\n\n\n"); - printf(">>date - This command prints the current date and time\n\n"); - printf(">>make - This command will make a file for you and you need to give command which type of extension do you want.\n\n"); - printf(">>remo - This command will remove a file\n\n"); - printf(">>list - This will print the files and folders in your directory\n\n"); - printf(">>wrte - This will write in the file you will give. Start writing the text with a space.\n\n"); - printf(">>wrta - This will append in your file. Start writing the text with a space and tehn write all the things which you want.\nFor example - Suppose there is hello initially written. So you want write hi with a space between hello and hi,\n so you should give two spaces before writing in the terminal\n\n"); - printf(">>quit - write quit and hit enter to exit the terminal\n\n"); - printf(">>pcwd - Print Current Working Directory\n\n"); - printf(">>ccwd - Change Current Working Directory\n\n"); - printf(">>mkdr - This will make a folder in the current directory\n\n"); - printf(">>rmdr - This will remove a folder in the current directory\n\n"); - printf(">>info - This will show you the details of the STerminal\n\n"); - printf(">>clr - This will clear the screen of the terminal\n\n"); - printf(">>read - This will print the content of the file.\n\n"); - printf(">>cnge - This will change your username and password\n\n"); - printf(">>copy - This will copy the contents of one file to another file.\n\n"); - printf(">>sys - This will print the information of your OS.\n\n"); - printf(">>echo - This will print anything which you have given. After writing echo press enter then write whatever you want and press enter.\n\n"); - printf(">>root - This will print the username and password\n\n"); - printf(">>rname - This will rename the file name you want.\n\n"); +#include + +//function to print the help menu. +void help() +{ + printf("\tIn all the cases first write the command hit enter and then give the arguements\n\n"); + + printf(">>calc - This command open a terminal calculator and you can do simple calculator operation in this.\n\tThe operaation are - (+, -, * , /, ^(Power of. Ex- 3^2 = 9)\n\tFirst number (operation) Second Number\n\tFor doing operation in decimal give d and for integer give i\n\n\n"); + printf(">>date - This command prints the current date and time\n\n"); + printf(">>make - This command will make a file for you and you need to give command which type of extension do you want.\n\n"); + printf(">>remo - This command will remove a file\n\n"); + printf(">>list - This will print the files and folders in your directory\n\n"); + printf(">>wrte - This will write in the file you will give. Start writing the text with a space.\n\n"); + printf(">>wrta - This will append in your file. Start writing the text with a space and tehn write all the things which you want.\nFor example - Suppose there is hello initially written. So you want write hi with a space between hello and hi,\n so you should give two spaces before writing in the terminal\n\n"); + printf(">>quit - write quit and hit enter to exit the terminal\n\n"); + printf(">>pcwd - Print Current Working Directory\n\n"); + printf(">>ccwd - Change Current Working Directory\n\n"); + printf(">>mkdr - This will make a folder in the current directory\n\n"); + printf(">>rmdr - This will remove a folder in the current directory\n\n"); + printf(">>info - This will show you the details of the STerminal\n\n"); + printf(">>clr - This will clear the screen of the terminal\n\n"); + printf(">>read - This will print the content of the file.\n\n"); + printf(">>cnge - This will change your username and password\n\n"); + printf(">>copy - This will copy the contents of one file to another file.\n\n"); + printf(">>sys - This will print the information of your OS.\n\n"); + printf(">>echo - This will print anything which you have given. After writing echo press enter then write whatever you want and press enter.\n\n"); + printf(">>root - This will print the username and password\n\n"); + printf(">>rname - This will rename the file name you want.\n\n"); } \ No newline at end of file diff --git a/list_file.h b/list_file.c similarity index 89% rename from list_file.h rename to list_file.c index 674bc75..38be640 100644 --- a/list_file.h +++ b/list_file.c @@ -1,26 +1,25 @@ -#include -#include -#include -#include -#include "change_dir_path.h" - - -//function to list all the files in the current directory. -void list() -{ - DIR *dir = opendir("."); - if (dir == NULL) - { - printf("Nothing in this directory\n\n"); - } - - struct dirent *entity; - entity = readdir(dir); - while (entity != NULL) - { - printf("%s\n", entity->d_name); - entity = readdir(dir); - } - printf("\n\n"); - closedir(dir); +#include +#include +#include +#include + + +//function to list all the files in the current directory. +void list() +{ + DIR *dir = opendir("."); + if (dir == NULL) + { + printf("Nothing in this directory\n\n"); + } + + struct dirent *entity; + entity = readdir(dir); + while (entity != NULL) + { + printf("%s\n", entity->d_name); + entity = readdir(dir); + } + printf("\n\n"); + closedir(dir); } \ No newline at end of file diff --git a/main.c b/main.c index a0d40ef..4a0c34e 100644 --- a/main.c +++ b/main.c @@ -3,27 +3,27 @@ Language: C */ //header files(some are inbuilt and some header files I have created to organize different codes) -#include "rename_file.h" -#include "userinfo.h" -#include "echo_file.h" -#include "system_info.h" -#include "copy_file.h" -#include "change_root.h" -#include "change_dir_path.h" -#include "help_file.h" -#include "open_file1.h" -#include "file_mkdr1.h" -#include "rmdr_file.h" -#include "make_file.h" -#include "wrta_file.h" -#include "wrte_file.h" -#include "list_file.h" -#include "calc_file.h" -#include "pcwd_file.h" -#include "clr_file.h" -#include "ccwd_file.h" -#include "remo_file.h" -#include "date_file.h" +#include "rename_file.c" +#include "userinfo.c" +#include "echo_file.c" +#include "system_info.c" +#include "copy_file.c" +#include "change_root.c" +#include "change_dir_path.c" +#include "help_file.c" +#include "open_file1.c" +#include "file_mkdr1.c" +#include "rmdr_file.c" +#include "make_file.c" +#include "wrta_file.c" +#include "wrte_file.c" +#include "list_file.c" +#include "calc_file.c" +#include "pcwd_file.c" +#include "clr_file.c" +#include "ccwd_file.c" +#include "remo_file.c" +#include "date_file.c" #include #include #include @@ -36,7 +36,7 @@ Language: C void main_loop() { //all the commands length are 5 characters so the command input will be taken from this variable. - char cmd_str[5]; + char cmd_str[4]; int stop = 0; //intializing stop = 0 so as to stop the while loop when it is 1. @@ -46,7 +46,7 @@ void main_loop() buf = (char *)malloc(100 * sizeof(char)); //I am using malloc as I don't know how much characters are there in the directory name. getcwd(buf, 100); //getcwd function is used here printf("[%s] $: ", buf); - + free(buf); //taking the command scanf("%s", cmd_str); @@ -156,7 +156,7 @@ int main() printf("Welcome to C terminal.\n\nTime:%s\n(Type help for manual or you can directly start interacting with terminal)\n\n", ctime(&t)); //setting of username and password - char username[10], password[10]; + char username[10], password[10], ch; FILE *root_passwd; root_passwd = fopen("password_root.txt", "r"); @@ -176,11 +176,12 @@ int main() printf("Give two enters after wrting the username and password.. Length of username should not exceed 10 charcters and password\nshould be of 6 characters.\n"); printf("USERNAME:- "); - gets(username); - getchar(); + fgets(username, 10, stdin); + username[strlen(username) -1] = 0; + printf("PASSWORD:- "); - gets(password); - getchar(); + fgets(password, 10, stdin); + password[strlen(password) - 1] = 0; fprintf(w_user, username); fprintf(wpasswd, password); @@ -195,8 +196,8 @@ int main() char password_existing[10], c1, c2; printf("Enter the password- "); - gets(password_existing); - getchar(); + fgets(password_existing, 10, stdin); + password_existing[strlen(password_existing) - 1] = 0; FILE *ptr; ptr = fopen("password_root.txt", "r"); diff --git a/make_file.h b/make_file.c similarity index 64% rename from make_file.h rename to make_file.c index c01990d..77d6905 100644 --- a/make_file.h +++ b/make_file.c @@ -1,14 +1,15 @@ -#include -#include - -void make() -{ - FILE *fp; - char name_file[30]; - getchar(); - printf("Enter file name with its extension:\n"); - gets(name_file); - - fp = fopen(name_file, "w"); - fclose(fp); -} +#include +#include + +void make() +{ + FILE *fp; + char name_file[25]; + getchar(); + printf("Enter file name with its extension:\n"); + fgets(name_file, 25, stdin); + name_file[strlen(name_file) - 1] = 0; + + fp = fopen(name_file, "w"); + fclose(fp); +} diff --git a/open_file1.c b/open_file1.c new file mode 100644 index 0000000..f8ff755 --- /dev/null +++ b/open_file1.c @@ -0,0 +1,35 @@ +#include +#include +#include + +void read_file(){ + getchar(); + FILE *fptr; + + char filename[25], c; + + printf("Enter the filename to open \n"); + fgets(filename, 25, stdin); + filename[strlen(filename) - 1] = 0; + + // Open file + fptr = fopen(filename, "r"); + if (fptr == NULL) + { + printf("Cannot open file \n"); + + } + else{ + // Read contents from file + c = fgetc(fptr); + while (c != EOF) + { + printf("%c", c); + c = fgetc(fptr); + } + + fclose(fptr); + printf("\n"); + } + +} \ No newline at end of file diff --git a/open_file1.h b/open_file1.h deleted file mode 100644 index a5b691c..0000000 --- a/open_file1.h +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -void read_file(){ - FILE *fptr; - - char filename[100], c; - - printf("Enter the filename to open \n"); - scanf("%s", filename); - - // Open file - fptr = fopen(filename, "r"); - if (fptr == NULL) - { - printf("Cannot open file \n"); - - } - - // Read contents from file - c = fgetc(fptr); - while (c != EOF) - { - printf("%c", c); - c = fgetc(fptr); - } - - fclose(fptr); - printf("\n"); -} \ No newline at end of file diff --git a/pcwd_file.h b/pcwd_file.c similarity index 89% rename from pcwd_file.h rename to pcwd_file.c index 02cb7a4..e86d337 100644 --- a/pcwd_file.h +++ b/pcwd_file.c @@ -1,25 +1,24 @@ -#include -#include -#include -#include -#include "change_dir_path.h" - - -//function to print the current directory. -void pcwd() -{ - if (change_dir == NULL) - { - char *buf; - buf = (char *)malloc(100 * sizeof(char)); - getcwd(buf, 100); - printf("%s\n\n", buf); - } - else - { - if (getcwd(change_dir, sizeof(change_dir)) != NULL) - { - printf("%s\n", change_dir); - } - } +#include +#include +#include +#include + + +//function to print the current directory. +void pcwd() +{ + if (change_dir == NULL) + { + char *buf; + buf = (char *)malloc(100 * sizeof(char)); + getcwd(buf, 100); + printf("%s\n\n", buf); + } + else + { + if (getcwd(change_dir, sizeof(change_dir)) != NULL) + { + printf("%s\n", change_dir); + } + } } \ No newline at end of file diff --git a/remo_file.c b/remo_file.c new file mode 100644 index 0000000..3d5610b --- /dev/null +++ b/remo_file.c @@ -0,0 +1,20 @@ +#include +#include +#include + +//function to remove a file +void remo() +{ + char name_file[30]; + printf("Enter the file name to delete: "); + getchar(); + fgets(name_file, 30, stdin); + name_file[strlen(name_file) - 1] = 0; + int check = remove(name_file); + if(!check){ + printf("Successfully deleted.\n"); + } + else{ + printf("Cannot delete.\n"); + } +} diff --git a/remo_file.h b/remo_file.h deleted file mode 100644 index 6b7e741..0000000 --- a/remo_file.h +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -//function to remove a file -void remo() -{ - char namr_file[30]; - printf("Enter the file name to delete: "); - getchar(); - gets(namr_file); - remove(namr_file); -} diff --git a/rename_file.h b/rename_file.c similarity index 58% rename from rename_file.h rename to rename_file.c index 356d119..054fcc5 100644 --- a/rename_file.h +++ b/rename_file.c @@ -8,18 +8,19 @@ void renameFile() char new_file_name[25]; int value; printf("Enter the name of the file(recent): "); - gets(old_file); - getchar(); + fgets(old_file, 25, stdin); + old_file[strlen(old_file) - 1] = 0; printf("Enter the new name of the file: "); - gets(new_file_name); + fgets(new_file_name, 25, stdin); + new_file_name[strlen(new_file_name) - 1] = 0; value = rename(old_file, new_file_name); if (!value) { - printf("File name changed successfully"); + printf("File name changed successfully\n"); } else { - printf("Error"); + printf("Error\n"); } } \ No newline at end of file diff --git a/rmdr_file.h b/rmdr_file.c similarity index 81% rename from rmdr_file.h rename to rmdr_file.c index 596a53c..301b757 100644 --- a/rmdr_file.h +++ b/rmdr_file.c @@ -1,27 +1,27 @@ -#include "change_dir_path.h" - -#include -#include -#include -#include -#define SIZE 25 - -//function to remove a directory. -void rmdr() -{ - int check; - char dirname[25]; - - printf("Enter a name of the folder:"); - getchar(); - gets(dirname); - check = rmdir(dirname); - - if (!check) - printf("Directory deleted\n"); - - else - { - printf("Unable to delete directory\n"); - } +#include +#include +#include +#include +#include +#define SIZE 25 + +//function to remove a directory. +void rmdr() +{ + int check; + char dirname[25]; + + printf("Enter a name of the folder:"); + getchar(); + fgets(dirname, 25, stdin); + dirname[strlen(dirname) - 1] = 0; + check = rmdir(dirname); + + if (!check) + printf("Directory deleted\n"); + + else + { + printf("Unable to delete directory\n"); + } } \ No newline at end of file diff --git a/system_info.h b/system_info.c similarity index 100% rename from system_info.h rename to system_info.c diff --git a/userinfo.h b/userinfo.c similarity index 100% rename from userinfo.h rename to userinfo.c diff --git a/wrta_file.c b/wrta_file.c new file mode 100644 index 0000000..11d6313 --- /dev/null +++ b/wrta_file.c @@ -0,0 +1,31 @@ +#include +#include + +//a function with which user can append into a file using the terminal. +void wrta() +{ + FILE *fp; + FILE *fptr; + char name_file[30]; + getchar(); + printf("Enter file name: "); + fgets(name_file, 30, stdin); + name_file[strlen(name_file) - 1] = 0; + fp = fopen(name_file, "r"); + if (fp == NULL) + { + printf("cannot open the file.\n"); + } + else + { + fptr = fopen(name_file, "a"); + char edits[300]; + printf("Write the text you want to append in your file. Start typing with a space..\n"); + fgetc(stdin); + fgets(edits, 300, stdin); + edits[strlen(edits) - 1] = 0; + fprintf(fptr, edits); + fclose(fptr); + } + fclose(fp); +} \ No newline at end of file diff --git a/wrta_file.h b/wrta_file.h deleted file mode 100644 index 6b130d5..0000000 --- a/wrta_file.h +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -//a function with which user can append into a file using the terminal. -void wrta() -{ - FILE *fp; - char name_file[30]; - getchar(); - printf("Enter file name: "); - gets(name_file); - fp = fopen(name_file, "a"); - char edits[300]; - printf("Write the text you want to append in your file. Start typing with a space..\n"); - getchar(); - gets(edits); - fprintf(fp, edits); - fclose(fp); -} \ No newline at end of file diff --git a/wrte_file.c b/wrte_file.c new file mode 100644 index 0000000..6d71c6f --- /dev/null +++ b/wrte_file.c @@ -0,0 +1,32 @@ +#include +#include +#include + +//a function with which user can write into a file using terminal. +void wrte() +{ + FILE *fp; + FILE *fptr; + char name_file[30]; + getchar(); + printf("Enter file name: "); + fgets(name_file, 30, stdin); + name_file[strlen(name_file) - 1] = 0; + fp = fopen(name_file, "r"); + if (fp == NULL) + { + printf("Cannot open file\n"); + } + else + { + fptr = fopen(name_file, "w"); + char edits[300]; + printf("Write the text what you want to be there in your file..\n"); + fgetc(stdin); + fgets(edits, 300, stdin); + edits[strlen(edits) - 1] = 0; + fprintf(fptr, edits); + fclose(fptr); + } + fclose(fp); +} \ No newline at end of file diff --git a/wrte_file.h b/wrte_file.h deleted file mode 100644 index 9545126..0000000 --- a/wrte_file.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - - -//a function with which user can write into a file using terminal. -void wrte() -{ - FILE *fp; - char name_file[30]; - getchar(); - printf("Enter file name: "); - gets(name_file); - fp = fopen(name_file, "w"); - - char edits[300]; - printf("Write the text what you want to be there in your file..\n"); - getchar(); - gets(edits); - fprintf(fp, edits); - fclose(fp); -} \ No newline at end of file