Hello i'm working on this piece of code and I have the idea how it should be. But I believe my assignment is base on boath C and shall formating command to create a menu. The code is working so far fine but in order to move on furthur. I need to know the proper syntax. I searched online and didn't find anything. I am trying to add operations menu or submenu. What is the command or system call used for this purpose.
After opening Directory , then File, I have to setup a menu in which opeitons are
Edit
Run
Change Directory
Make New Subdirectory
Remove File
Quit
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
#include <curses.h>
int main(void){
////Variables////
///////////////////////
pid_t child;
DIR * d;
struct dirent * de;
int i,c, k;
char s[256], cmd[356];
time_t t;
//////////////////////
while(1){
t= time (NULL);
printf("Time: %s \n", ctime(&t));
getcwd(s,200); //why 200? what if bigger? check for errors?
printf("\n Current Directory: %s \n", s);
d= opendir(".");
c = 0;
while((de = readdir(d))){
if ((de->d_type) & DT_DIR)
printf("( %d Directory: %s )\n", c++, de-> d_name);
}
closedir(d);
d = opendir( ".");
c = 0;
while((de = readdir(d))){
if(((de->d_type) & DT_REG))
printf("(%d File: %s) \n", c++, de->d_name);
if((c % 8 )==0){
printf("Hit N for Next \n");
k = getchar();}
}
closedir(d);
printf(" ____________________________\n");
c =getchar();getchar();
switch (c) {
case 'q': exit(0); /*quit */
case 'e': printf("Edit what?:" );
scanf("%s", s);
strcpy(cmd, "pico");
strcat(cmd,s);
system(cmd);
break;
case 'r': printf("Run What?;" );
scanf("%s",cmd);
system(cmd);
break;
case 'c': printf("Change To?:");
scanf("%s",cmd);
chdir(cmd);
break;
}
}
return 0;
}