cin.ignore();
cout << "Enter lecture notes/tutorials location.\n";
cout << "e.g C:/Lecture Notes/lecture01.ppt";
cout << ">>>";
getline(cin,lectut_loca);
cout << "Enter lecture notes/tutorials name: ";
cout << "e.g lecture01.ppt";
cout << ">>>";
getline(cin,lectut_name);
string copy = "copy";
copier = copy + " " + lectut_loca + " " + lectut_name;
const char *copier;
cout << copier;
getch();
system(copier);
cout << "\nLecture notes/tutorials added.";

the const char *copier; i use copier = copier.c_str(); but get error on system(copier); when compiling. then i use const char *copier; no error compile but runtime error!

:lol:

what should i do?

cin.ignore();
cout << "Enter lecture notes/tutorials location.\n";
cout << "e.g C:/Lecture Notes/lecture01.ppt";
cout << ">>>";
getline(cin,lectut_loca);
cout << "Enter lecture notes/tutorials name: ";
cout << "e.g lecture01.ppt";
cout << ">>>";
getline(cin,lectut_name);
string copy = "copy";
 copier = copy + " " + lectut_loca + " " + lectut_name;
// using variable before declaring it is not allowed in your case copier.

 const char *copier; // initialisation of const variables must be done 
                            // during declaration intself eg. const int i = 8 ;
 cout << copier;
 getch(); // getch() is non portable use cin.get ()
system(copier);
cout << "\nLecture notes/tutorials added.";

what should i do?

Look at the things i have mentioned above.
And maybe you should look at this simple expample.

string my_copy = "copy" ;
my_copy += " " + lectut_loca + " " + lectut_name ;
const char* copier = my_copy.c_str() ;
system (copier) ;

Hope ti helped, bye.

PS: looks like you are trying to implement the copy function of DOS.
;)

Look at the things i have mentioned above.
And maybe you should look at this simple expample.

string my_copy = "copy" ;
my_copy += " " + lectut_loca + " " + lectut_name ;
const char* copier = my_copy.c_str() ;
system (copier) ;

Hope ti helped, bye.

PS: looks like you are trying to implement the copy function of DOS.
;)

yah.. should be like that? urmm.. syntax error! :confused:

add

char a='"';
strcat(a, copier);
strcat(copier, a);

hahaha.. compile error!

I dont get you...
Are you saying even after making the changes you get a syntax error ???

Error messages come with line numbers.
Use those line numbers to find out where in the code the problem is. Any editor should have a "goto line" feature, or at least display line numbers in some manner.

Post code (annotated with line numbers if necessary) along with exact error messages if you're still stuck.

yes.. after making the change.

error in runtime.. The syntax of the command is incorrect.

add

char a='"';
strcat(a, copier);
strcat(copier, a);

hahaha.. compile error!

Umm... buddy, what exactly are you trying to do. strcat funtion expects you to supply both parameters as char* ie char pointers and you supplying it a char.

You can get its prototype here: http://www.cppreference.com

Post your complete program from start to finish with the header files and then maybe i could pinpoint the mistake.

the staff module...

//the staff module

#include "staff.h"
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

class sfunction
{
      private:
              string lectut_loca;
              string lectut_id;
              string lectut_name;
              
              string announce_id;
              string announce_subject;
              string announce_desc;
              
      public:
             void add_lec_tut()
             {
                  string copier;
                  display_title("Add Lecture Notes/Tutorials");
                  cout << "Please enter course id: ";
                  cin >> lectut_id;
                  for(int i=1; i<=count_line("course.MOLS"); i++)
                  {
                          if(gettok( read("course.MOLS", i), ';', 1) == lectut_id)
                          {
                               cin.ignore();
                               cout << "Enter lecture notes/tutorials location.\n";
                               cout << "e.g C:/Lecture Notes/lecture01.ppt";
                               cout << ">>>";
                               getline(cin,lectut_loca);
                               cout << "Enter lecture notes/tutorials name: ";
                               cout << "e.g lecture01.ppt";
                               cout << ">>>";
                               getline(cin,lectut_name);
                               string my_copy = "copy" ;
                               my_copy += " " + lectut_loca + " " + lectut_name ;
                               const char* copier = my_copy.c_str() ;
                               cout << copier;
                               system(copier);
                               cin.get();                               
                               cout << "\nLecture notes/tutorials added.";
                               getch(); break;
                          }
                          else if(i==count_line("course.MOLS"))
                          {
                               cout << lectut_id << " not found!";
                               getch();
                          }
                  }
                  
                  
                  
                  getch();
                  
             };
             void edit_lec_tut()
             {
                  display_title("Edit Lecture Notes/Tutorials");
                  getch();
             };
             void del_lec_tut(){};
             
             void add_announ()//add announcement(s)
             {
                  display_title("Add Announcements");
                  cout << "Please enter course id: ";
                  cin >> announce_subject;
                  for(int i=1; i<=count_line("course.MOLS"); i++)
                  {
                          if(gettok( read("course.MOLS", i), ';', 1) == announce_subject)
                          {
                               cout << "Plase enter announcement id: ";
                               cin >> announce_id;
                               cin.ignore();
                               cout << "Please enter your announcement: ";
                               getline(cin,announce_desc);
                               write("Lecturer/announcement.MOLS", i, announce_id + ";" + announce_subject + ";" + announce_desc);
                               cout << "\nAnnouncement added.";
                               getch(); break;
                          }
                          else if(i==count_line("course.MOLS"))
                          {
                               cout << announce_subject << " not found!";
                               getch();
                          }
                  }
             };
             
             void edit_announ()
             {
                  display_title("Add Announcements");
                  cout << "Enter course id: ";
                  cin >> announce_subject;
                  for(int i=1; i<=count_line("Lecturer/announcement.MOLS"); i++)
                  {
                          if(gettok( read("Lecturer/announcement.MOLS", i), ';', 2) == announce_subject)
                          {
                               cout << "Previous announcement:\n"
                               << gettok( read("Lecturer/announcement.MOLS", i), ';', 3) << endl;
                               cout << "\nEnter new announcement id: ";
                               cin >> announce_id;
                               cin.ignore();
                               cout << "Enter new announcement: ";
                               getline(cin,announce_desc);
                               write("Lecturer/announcement.MOLS", i, announce_id + ";" + announce_subject + ";" + announce_desc);
                               cout << "\nAnnouncement added.";
                               getch(); break;
                          }
                          else if(i==count_line("Lecturer/announcement.MOLS"))
                          {
                               cout << announce_subject << " not found!";
                               getch();
                          }
                  }
             };
             void del_announ()
             {
                  display_title("Delete Announcements");
                  cout << "Enter announcement id: ";
                  cin >> announce_id;
                  for(int i=1; i<=count_line("Lecturer/announcement.MOLS"); i++)
                  {
                          if(gettok( read("Lecturer/announcement.MOLS", i), ';', 1) == announce_id)
                          {
                                     del("Lecturer/announcement.MOLS", i);
                                     cout << "Announcement succesfully deleted!";
                                     getch();
                          }
                  }
             };
             void add_assign(){};
             void edit_assign(){};
             void del_assign(){};
};

and the staff header

#ifndef    _STAFF_H_
#define    _STAFF_H_
#include "staff.cpp"
#endif

So where is your int main (void) function and what problems are you facing with this code, and if facing compile time problems mark the line which flags the error in red so taht we can see it and if run time error then describe it.

run time error

after i input the lecture notes/tutorials name..
(getline(cin,lectut_name);

it show>>> The syntax of the command is incorrect.

> cout << copier;
Why didn't this appear to output anything?

> system(copier);
If the string is garbage in any way, then you'll get that error message.

> string my_copy = "copy" ;
> my_copy += " " + lectut_loca + " " + lectut_name ;
Starting with a string constant is perhaps a bad idea. + is oveloaded for both char * pointer addition (the type of " ") and std::string concatenation (your strings). The compiler might pick the wrong one.
Try

string my_copy = "copy " ;
my_copy += lectut_loca + " " + lectut_name ;

Windows works with backslashes "\" and forward slashes "/" but you better use Backslashes.

And also looking at your "command string" dump i can clearly see the problem. YOu are passing something like "copyA.txt B.txt" which is not the correct syntax fro the DOS copy command.

The actual syntax is "copy source dest" with spaces present in between. You can find the syntax for all commands here
http://www.easydos.com/copy.html

For testing purpose try out inputting
YServer.txt as the first input and server.txt as the second input and watch what output is displayed.

yah.. it's work with backslash.. hahaha.. pity me..

because no dest so the file copied to current folder which program is running..

thanks you guys!!!

Glad we could be of assistance and most of the credit of this problem solved goes to Mr. Salem for pointing out that it was actually the command string which was getting messed up, I just picked up his idea and completed it for you.

Best of luck.

copy c:\yserver.txt c:\documents and settings\luffy-san\desktop\tcp1241_assignment3\lecture notes\server.txt

not working...

copy c:\yserver.txt c:\temp\server.txt

working... what is the problem?

Well judging from the colour scheme from your output examples, my guess is you're using some crusty old Turbo C compiler on a nice new XP based system.

Problem number 1
Turbo C knows nothing about long filename, nor filenames with spaces.

It should be paying attention to the COMSPEC environment variable (which should be say ComSpec=C:\WINDOWS\system32\cmd.exe but I guess your compiler sets it to the far inferior command.com (because that's the historic answer for the historic compiler. Command.com didn't know anything about long filenames or space in filenames either.

And this is only one of many possible compatibility problems you'll face with this compiler.

Get a modern 32-bit compiler, one which is far more compatible with your operating system.

There is nothing wrong with your program, it is the command which is incorrect. Do some research on the DOS Copy command to find out the valid commands and the format of the command. Look at the link which i had given in my 4th or 5th post on the previous page.

Hope it helped, bye.

@Mr. Salem : What is the difference if the compiler is 16 bit or 32 bit since the "copy" command which is executed in DOS mode runs in 16 bit. Try out the commands written by the guy in the DOS window without the program, jsut type it and still it doesnt work so i guess no mistake of teh compiler.
But then again maybe i am wrong somewhere, please let me know where it is?

Not sure whether it would work for TurboC and the old command.com shell, but you could try creating the command using double quotes to handle filenames with spaces. Don't know what will happen for long file names though.

e.g.

copy [B]"[/B]c:\yserver.txt[B]"[/B] [B]"[/B]c:\documents and settings\luffy-san\desktop\tcp1241_assignment3\lecture notes\server.txt[B]"[/B]
commented: good one [~sos~] +4
commented: Good answer - beat me to it - Salem :) +3

Mmm

$ dir
 Volume in drive C has no label.
 Volume Serial Number is F8A8-3449

 Directory of C:\temp

25/09/2006  19:00    <DIR>          .
25/09/2006  19:00    <DIR>          ..
25/09/2006  18:58                 2 my long filename.txt
               1 File(s)              2 bytes
               2 Dir(s)  13,895,516,160 bytes free

$
$ copy "my long filename.txt" test.txt
        1 file(s) copied.

$ command.com
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp 1990-2001.

$ copy "my long filename.txt" test2.txt
        1 file(s) copied.

$ exit

Maybe it's just enough if you surround the long filename with double quotes.
But bear in mind that command.com also has a limit (like 128 characters) on the length of any command line, so there could still be problems.

Not sure whether it would work for TurboC and the old command.com shell, but you could try creating the command using double quotes to handle filenames with spaces. Don't know what will happen for long file names though.

e.g.

copy [B]"[/B]c:\yserver.txt[B]"[/B] [B]"[/B]c:\documents and settings\luffy-san\desktop\tcp1241_assignment3\lecture notes\server.txt[B]"[/B]

Yep it works. Dont know where you found out about this one but this sure is informative, hats off (and of course rep)to you.

Your friend,

~s.o.s~

Dont know where you found out about this one

Nothing like getting bitten once or twice while writing a bat(cmd) script.

wahhh!! thanks again.. actually i'm using dev cpp compiler 4.9.9.2 .. a 32 bit compiler right?

the output screen tweaked with system("color 1F");

> actually i'm using dev cpp compiler 4.9.9.2 .. a 32 bit compiler right?
Yes it is.

So just using double quotes should be good.

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.