LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A program to create a text file (https://www.linuxquestions.org/questions/programming-9/a-program-to-create-a-text-file-916009/)

darkhorse92 11-28-2011 10:21 AM

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!!

dwhitney67 11-28-2011 10:29 AM

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.

bigearsbilly 11-28-2011 10:36 AM

microsoft word?

darkhorse92 11-28-2011 10:57 AM

nope its done in Microsoft Visual Studio

darkhorse92 11-28-2011 11:00 AM

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.

Proud 11-28-2011 11:33 AM

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.

TB0ne 11-28-2011 11:34 AM

Quote:

Originally Posted by darkhorse92 (Post 4536458)
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.

SigTerm 11-28-2011 12:25 PM

Quote:

Originally Posted by darkhorse92 (Post 4536458)
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.

tarunchawla 11-29-2011 07:13 AM

bro try something atleast write a wrong code then we will help you surely...

Juako 11-29-2011 07:39 AM

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.

theNbomr 11-29-2011 10:41 AM

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.

b0uncer 11-29-2011 12:01 PM

Quote:

Originally Posted by darkhorse92 (Post 4536458)
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.


All times are GMT -5. The time now is 08:18 AM.