Ok well i need help with my code, the idea is to make something like a DOS Console, the trick is we are not alowed to use dos functions.

Well this is what i have so far

#include <stdio.h>
 #include <iostream.h>
 #include <conio.h>
 #include <string.h>
 #include <dir.h>
 #include <dos.h>
 #include <errno.h>
 #include <io.h>
 #include <process.h>
 #include <sys\stat.h>

 void clear();
 void chatt();
 char directory();
 void cdd();
 void deletee();
 void cdup();
 void time();
 void date();
 void dir();
 void create();
 void copy();
 void deleteee();
 void watchatt();
 void renamee();

 void main()
 {   char z,* texto;
     int q,t,error;
     q=0;
     while(q==0)
     {
	 directory();
	 error=1;
	 fflush(stdin);
	 gets(texto);
	 cout<<"";
	 t=strcmp(texto,"");
	 if(t==0)
	     error=0;
	 t=strcmp(texto,"erase");
	 if(t==0)
	 {   deletee();
	     error=0;
	 }
	 t=strcmp(texto,"exit");
	 if(t==0)
	 {   q++;
	     error=0;
	 }
	 t=strcmp(texto,"cd");
	 if(t==0)
	 {
	     cdd();
	     error=0;
	 }
	 t=strcmp(texto,"cd..");
	 if(t==0)
	 {   cdup();
	     error=0;
	 }
	 t=strcmp(texto,"attrib");
	 if(t==0)
	 {
	    watchatt();
	    error=0;
	 }
	 t=strcmp(texto,"dir");
	 if(t==0)
	 {
	    dir();
	    error=0;
	 }
	 t=strcmp(texto,"clear");
	 if(t==0)
	 {
	   clear();
	   error=0;
	 }
	 t=strcmp(texto,"chmod");
	 if(t==0)
	 {
	    chatt();
	    error=0;
	 }
	 t=strcmp(texto,"rename");
	 if(t==0)
	 {
	    renamee();
	    error=0;
	 }
	 t=strcmp(texto,"create");
	 if(t==0)
	 {
	    create();
	    error=0;
	 }
	 t=strcmp(texto,"date");
	 if(t==0)
	 {
	    date();
	    error=0;
	 }
	 t=strcmp(texto,"copy");
	 if(t==0)
	 {
	   copy();
	   error=0;
	 }
	 t=strcmp(texto,"time");
	 if(t==0)
	 {
	   time();
	   error=0;
	 }
	 t=strcmp(texto,"del");
	 if(t==0)
	 {
	   deleteee();
	   error=0;
	 }
	 if(error==1)
	      cout<<"El comando es invalido\n";

     }
 }
 char directory()
 {
  char dire[128];
  getcwd(dire, 128);
  cout<<dire<<":";
  return 0;
 }
 void cdd()
 {
   char *route;
   cin>>route;
   chdir(route);
 }
 void cdup()
 {
    chdir("..");
 }
 void deletee()
 {
     int x,y;
     for(x=0;x<=80;x++)
	 for(y=0;y<=100;y++)
	 {   gotoxy(x,y);
	     printf(" ");
	     gotoxy(1,1);
	 }
 }

 void dir()
 {

     struct ffblk ffblk;
     int done;
     cout<<"Directory list\n";
     done = findfirst("*.*",&ffblk,0);
     while (!done)
     {
       cout<< ffblk.ff_name<<endl;
	 done = findnext(&ffblk);
     }
 }
 void clear()
 {
   clrscr();
 }
 void create()
 {
   char *newdir;
   cin>>newdir;
   mkdir(newdir);
 }
 void copy()
 {

   char src[64];
   char dest[64];
   cout<<"File to copy: ";
   gets(src);
   cout<<"Destination: ";
   gets(dest);

 }
 void deleteee()
 {

 }
 void watchatt()
 {
    unsigned attrib;
    char fileatt [64];
    cout<<"Name of the file";
    cin>>fileatt;
    _dos_getfileattr(fileatt,&attrib);
    if(attrib & _A_RDONLY)
    cout<<"File is read only"<<endl;
    if(attrib & _A_HIDDEN)
    cout<<"File is hidden"<<endl;
    if(attrib & _A_SYSTEM)
    cout<<"File is from the system"<<endl;
    if(attrib & _A_VOLID)
    cout<<"File is a volume label"<<endl;
    if(attrib & _A_SUBDIR)
    cout<<"File is a directory"<<endl;
    if(attrib & _A_ARCH)
    cout<<"File is an archive"<<endl;
 }
 void chatt()
 {
   char filename1[64];
   char fileop, op;
   struct stat stbuf;
   int amode;

   cout<<"Name of file: ";
   cin>>filename1;
   if(stat(filename1,&stbuf)!=0)
   {
      cout<<"Unable to get file information"<<endl;
      exit(1);
   }
   if(stbuf.st_mode & S_IWRITE)
   {
      cout<<"File is a read and write"<<endl<<"Would you like to change it? ";
      cin>>fileop;
      switch(fileop)
      {
	case 'Y':
	cout<<"Choose your option: ";
	cout<<"\n 1. Read Only";
	cout<<"\n 2, Exit";
	cin>>op;
	switch(op)
	{
	  case '1':
	  amode=S_IREAD;
	  break;
	  default:
	  cout<<"Going out";

	}
	default: "Going out";

      }
   }
   if(stbuf.st_mode & S_IREAD)
   {
      cout<<"File is a read only"<<endl<<"Would you like to change it? ";
      cin>>fileop;
      switch(fileop)
      {
	case 'Y':
	cout<<"Choose your option: ";
	cout<<"\n 1. Read and Write";
	cout<<"\n 2, Exit";
	cout<<endl;
	cin>>op;
	switch(op)
	{
	  case '1':
	  amode=S_IWRITE;
	  break;
	  default:
	  cout<<"Going out";
	}
	default: "Going out";
      }
   }
   if(chmod(filename1,amode) != 0 )
   {
     cout<<"Unable to change file mode";

   }

 }
 void time()
 {
    struct time t;
    int newtime[4];
    int cht;
    char y_n;
    gettime(&t);
    int j=0;

    newtime[0]=t.ti_hour;
    newtime[1]=t.ti_min;
    newtime[2]=t.ti_sec;
    newtime[3]=t.ti_hund;
    cout<<"The current time is: ";
    for (int i=0;i<4;i++)
    {
       cout<<newtime[i]<<":";
    }

    cout<<"\n Would you like to modify the time?";
    cout<<"\n Yes = y";
    cout<<"\n No = n";
    cin>>y_n;
    if(y_n=='y')
    {
     while(cht!=27)
     {
       cht=getch();
       if(cht==80)
       {
	newtime[j] =t.ti_hour--;
	settime(&t);
       }
       if(cht==72)
       {
	newtime[j]=t.ti_hour++;
	settime(&t);
       }
       if(cht==77)
       {
	 j++;
       }
       if(cht==80)
       {
	newtime[j] =t.ti_min--;
	settime(&t);
       }
       if(cht==72)
       {
	newtime[j]=t.ti_min++;
	settime(&t);
       }
       if(cht==80)
       {
	newtime[j] =t.ti_sec--;
	settime(&t);
       }
       if(cht==72)
       {
	newtime[j]=t.ti_sec++;
	settime(&t);
       }
       if(cht==80)
       {
	newtime[j] =t.ti_hund--;
	settime(&t);
       }
       if(cht==72)
       {
	newtime[j]=t.ti_hund++;
	settime(&t);
       }
       if(cht==77&&j==3)
       {
	cout<<"You can only go back now!";
       }
       if(cht==75)
       {
	j--;
       }
       if(cht==75&&j==0)
       {
	cout<<"You can only move forward!";
       }
       if(cht==13)
       {
	 cout<<"The current time is: ";
	 for (int i=0;i<4;i++)
	 {
	     cout<<newtime[i]<<":";
	 }
	 cht=27;
       }
     }
    }
    cout<<endl;
 }
 void date()
 {

    struct date d;
    struct date d2;
    int newdate[3];
    int chd;
    char y_n;
    getdate(&d2);
    getdate(&d);
    int j=0;

    newdate[0]=d.da_day;
    newdate[1]=d.da_mon;
    newdate[2]=d.da_year;

    cout<<"The current time is: ";
    for(int i=0;i<3;i++)
    {
      cout<<newdate[i]<<".";
    }

    cout<<"\n Would you like to modify the date?";
    cout<<"\n Yes = y";
    cout<<"\n No = n";
    cin>>y_n;
    if(y_n=='y')
    {
     while(chd!=27)
     {
       chd=getch();
       if(chd==80)
       {
	newdate[j] =d.da_day--;
	setdate(&d);
       }
       if(chd==72)
       {
	newdate[j]=d.da_day++;
	setdate(&d);
       }
       if(chd==77)
       {
	 j++;
       }
       if(chd==80)
       {
	newdate[j] =d.da_mon--;
	setdate(&d);
       }
       if(chd==72)
       {
	newdate[j]=d.da_mon++;
	setdate(&d);
       }
       if(chd==80)
       {
	newdate[j] =d.da_year--;
	setdate(&d);
       }
       if(chd==72)
       {
	newdate[j]=d.da_year++;
	setdate(&d);
       }
       if(chd==77&&j==2)
       {
	cout<<"You can only go back now!";
       }
       if(chd==75)
       {
	j--;
       }
       if(chd==75&&j==0)
       {
	cout<<"You can only move forward!";
       }
       if(chd==13)
       {
	 cout<<"The current time is: ";
	 system("date");
	 chd=27;
       }
     }
    }
 }
 void renamee()
 {
   char oldname[64], newname[64];

   cout<<"Enter the name of the file to modify: ";
   gets(oldname);
   cout<<"\n Enter the new name: ";
   gets(newname);

   if(rename(oldname,newname)==0)
     cout<<"File "<<oldname<<" is now called: "<<newname<<endl;
   else
     cout<<"error"<<endl;
 }

What i need help with is to copy and delete. I was planing on using the SHFileOperation but i'm not familiar with it.
If someone could help me i would really apreciate it, also if anyone know how to make the program code look a little bit more goodlooking i would apreaciate that too.

> void main()
> { char z,* texto;
> fflush(stdin);
> gets(texto);
Wow, the unholy trinity all together in such a short sequence of code.
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044841143&id=1043284376
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351
Worse still, you pass an UNINITIALISED pointer to gets(), so the whole thing is poisoned before you even type a single character.

Nor is it the only place where you just declare a pointer and then attempt to read user input into where it points.

These are serious deficiencies in your skills. You need to work on the basics of programming before actually tackling anything of substance.

> #include <stdio.h>
> #include <iostream.h>
So which is it, C OR C++ ?
Choose one of them.
Random mixes of both won't do you any favours.

Well im supposed to use C++ besides all the code in the Main is not mine is from a person from my group, im just working on the functions, but since you brought it up and seem to be real good, could you tell me wich should i take out and wich should i leave in or how to replace the once on mentioned.

Thank you for the reply, sry about the mixed code.

Member Avatar for iamthwee

Looks like another turbo c user.

Terrible!

The IDE is not something you can choose for this proyect, it is turbo C or nothing.
Im guessing im not going to get any help so...
Thank you
See you all laterz.

Member Avatar for iamthwee

Yeah there seriously isn't any point giving you any advice because you're constrained by the monstrosities of your compiler/ide.

Turbo c, well the antiquated version, can't even handle std::strings etc, it is at best a bastardized version of c and c++. Bits of c++ works in turbo c, but at best it is a guess and because of this you end up writing a terrible mixture of c and c++, where sometimes it can be damn right dangerous.

All you need to realise is, that what you're writing at the moment is non-standard.

Unfortunately, for someone to help you properly, without guessing, they'd probably have to download turbo c. *brrrr*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.