LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2006, 06:28 AM   #1
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Rep: Reputation: 15
write interactive c++


hi. i hope i can get help to write an interactive c++ program that enables me to accept two arguments. one argument is source file and the other one is destination file. i've never done anything like this before. help. please. thanks
 
Old 06-20-2006, 06:32 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
What do you mean by "interactive"? Command line interaction? Graphical User Interface (GUI)?
 
Old 06-20-2006, 06:34 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
int main(int argc, char *argv[])
{
char *source = argv[1];
char *destination = argv[2];

// put your processing here

return 0;
}

You can use getopt for advanced command line parsing and readline for interaction with the user (text mode).

Do you have more specific questions because frankly I don't get what you are asking for.

Last edited by Agrouf; 06-20-2006 at 06:36 AM.
 
Old 06-20-2006, 08:52 AM   #4
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Original Poster
Rep: Reputation: 15
well i am asked to write an interactive c++ program that accepts two arguments using command line interaction. i'm suppose to get the source and destination file there and copy from one file to another. if user does not enter two arguments, an error message will occur. for instance, when i want to compile the program i use g++ prg.cpp -o prg then if i type only ./prg the next line, an error message will occur. it must be ./prg source file.

Agrouf, your codes
Quote:
int main(int argc, char *argv[])
{
char *source = argv[1];
char *destination = argv[2];

// put your processing here

return 0;
}
what is int argc for? thanks.
 
Old 06-20-2006, 10:58 AM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
Is that homework?

Anyway, argc and argv go hand in hand together.
Read that http://www.aims.ac.za/resources/tuto...emory/main.php (found on google with "C main function").

You will need to use the fstream class. google for that for more informations. I'll be glad to help if you have specific questions.
 
Old 06-20-2006, 12:03 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
Gotta be. Ask your teacher!

Dig a little bit... don't ask someone else to spoon the answer to you.
 
Old 06-21-2006, 04:13 AM   #7
christina_rules
LQ Newbie
 
Registered: May 2006
Posts: 25

Original Poster
Rep: Reputation: 15
thanks. yeah it's homework. and i'm weak in programming. but thanks for the help
 
Old 06-21-2006, 01:07 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.

And as other members already pointed out: don't expect people here to do
your homework; that's against the rules that you agreed to when signing up.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Interactive installation hemazutshi Linux - Newbie 1 03-31-2006 10:37 AM
Please help with interactive script moosedaddy Linux - Newbie 3 12-08-2005 09:02 PM
non-interactive ssh podollb Linux - Software 3 04-20-2004 03:28 PM
Interactive setup EECGeek Linux - Newbie 4 01-20-2004 09:15 PM
Non interactive FTP lapthorn Linux - Networking 1 11-28-2003 12:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration