LinuxQuestions.org
Help answer threads with 0 replies.
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 11-28-2011, 10:21 AM   #1
darkhorse92
LQ Newbie
 
Registered: Nov 2011
Posts: 14

Rep: Reputation: Disabled
Unhappy A program to create a text file


Due to the bad and fast teaching of my professor i am unable to catch up with him. And he just simply gives up work which carry lots of marks.
My problem is i cannot figure out how to do this program, and this one is real different from the one i used to do previously. The description of the program is below.

"Write a program that creates a text file containing the printed ASCII values of the data from a binary file, Take in an input file name as the first (and only) argument on the command line using argc and argv in main(). This file must be opened as a binary file. If the filename is not found on the command line, display an error message and quit the program"

Please help me finish this or i will be in a trouble loosing lots of marks. If some one wants more information about the requirement please let me know!!
 
Old 11-28-2011, 10:29 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Sorry, but this forum does not support requests for completing homework assignments. If you have a particular problem with code that you have already written, and need help getting over it, please do let us know.

Now, as for your assignment, try to break it down into smaller sub-tasks.

1. Define your program to include a main() function; this function should accept two parameters: argc and argv.

2. Add code to check if a parameter has been passed to your program; argc contains the number of arguments that are passed to the program. The program name itself is always the first argument, thus at a minimum, argc will be equal to 1. For your assignment, you require that argc equal 2. The list of arguments that are passed to the program are accessible via argv. argv[0] is the program name, argv[1] is the next argument, etc.

3. At this point, you should have a program that compiles and is able to run. You should test it without supplying a command-line argument, and again by supplying one (ie. a filename).

Post back to this forum when done with step 3 (please show code within CODE tags), and then we can proceed to discuss the other matters of your assignment.
 
1 members found this post helpful.
Old 11-28-2011, 10:36 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
microsoft word?
 
0 members found this post helpful.
Old 11-28-2011, 10:57 AM   #4
darkhorse92
LQ Newbie
 
Registered: Nov 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
nope its done in Microsoft Visual Studio
 
0 members found this post helpful.
Old 11-28-2011, 11:00 AM   #5
darkhorse92
LQ Newbie
 
Registered: Nov 2011
Posts: 14

Original Poster
Rep: Reputation: Disabled
bigearsbilly can u make the program for me? i really don't know how to do this one!!
I recently joined the programming course (so i am a noob) and my professor is expecting us to know everything, and i must say this one a difficult and i need more time to learn how to do this.
 
0 members found this post helpful.
Old 11-28-2011, 11:33 AM   #6
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
I think bigears was joking that Word.exe is a program that takes a 'binary' format (what isn't binary?) and can output ASCII.

See dwhitney67's post, if you can't manage that, you are on the wrong course. We won't do your work, we will only help you learn to do it yourself.
 
Old 11-28-2011, 11:34 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by darkhorse92 View Post
bigearsbilly can u make the program for me? i really don't know how to do this one!!
I recently joined the programming course (so i am a noob) and my professor is expecting us to know everything, and i must say this one a difficult and i need more time to learn how to do this.
Lots of folks here CAN write it for you. However, this is not OUR school work, it's yours. If you can't do it, tell the professor, and get help. Use your textbooks. YOU have to learn, not get handed the answer.

If you have a SPECIFIC problem, come back, post what you've done, and where you're stuck, and we'll all be happy to help you.
 
Old 11-28-2011, 12:25 PM   #8
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by darkhorse92 View Post
bigearsbilly can u make the program for me?
Look, even if somebody made a program for you, you would still fail the course later, because this way you won't learn required material. Do a research, find few C/C++ tutorials, get a book about C/C++, read it, and start writing. It isn't that hard. You could also probably ask professor for help/advice (you know - catch him after lectures and ask), or ask more experienced student for help/tutoring. Instead you want people to do your homework for nothing.

Last edited by SigTerm; 11-28-2011 at 12:27 PM.
 
1 members found this post helpful.
Old 11-29-2011, 07:13 AM   #9
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Rep: Reputation: 3
bro try something atleast write a wrong code then we will help you surely...
 
Old 11-29-2011, 07:39 AM   #10
Juako
Member
 
Registered: Mar 2010
Posts: 202

Rep: Reputation: 84
darkhorse92: pay attention to dwhitney67's post, those are the steps to get to half of the assignment, which *really* is a very simple, intro-to-C type task (no, I'm no guru nor "expert"). What have you come up with until now? You say it's different from the earlier program, but if that was done in C too, at least you know how to write the main() function, that's something.
 
Old 11-29-2011, 10:41 AM   #11
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Start by reading the man pages for open(), read(), write(), close(), and printf(). These are the principle standard C functions that you will require.
Code:
man 2 open
man 2 read
man 2 write
man 3 printf
You could alternatively use the fopen()/fscanf()/fprintf()/fclose() class of C functions.

--- rod.

Last edited by theNbomr; 11-29-2011 at 01:17 PM.
 
Old 11-29-2011, 12:01 PM   #12
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Quote:
Originally Posted by darkhorse92 View Post
bigearsbilly can u make the program for me? i really don't know how to do this one!!
I recently joined the programming course (so i am a noob) and my professor is expecting us to know everything, and i must say this one a difficult and i need more time to learn how to do this.
So you were going to continue like that in the real life as well? "X can u [...] for me? i really don't know how to [...]" (supplement [...] with "breed" and you'll get it...)

The task is not difficult. Actually it is a very primitive exercise, so the course cannot possibly be very difficult, unless you take giant leaps, and lots of them. Therefore your professor cannot expect you to know everything (otherwise your professor would ask you to craft a program that could predict correct lottery numbers, or something); the problem is probably you, having always taken the easy way, not learning anything. Either that, or then you're taking courses meant for older students than you. Either way, you must simply do it yourself (and learn), step by step, through mistakes, or quit and for a second think about what you're doing.

If you can't do anything else, write a hello world program (no, do not copy an example, but write it yourself). Then think about the arguments and ask for more help. But if you're on a "introduction to programming/C/something else" course and cannot do this, don't expect much...these courses are not passed by obtaining maximum number of "marks", but by learning, which then "automatically" earns you marks.

It doesn't matter whether you use MS Visual Studio or Vi+gcc or something else. In fact, you could choose your programming language quite freely and still be able to complete the task. If you don't understand that, you have problems.
 
  


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
cannot create regular file ...: text file busy laode Linux - General 4 11-27-2012 01:56 AM
How do I create a duplicate file of a text file in PHP? puppymagic Programming 1 11-11-2010 01:56 AM
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-10-2008 11:13 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM
in Pascal: how to exec a program, discard text output or send to text file Valkyrie_of_valhalla Programming 6 05-02-2007 09:50 AM

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

All times are GMT -5. The time now is 09:52 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