CS19001/CS19002 Programming and Data Structures Laboratory | Autumn/Spring semester |
How to take print-outs
- In your C program write your name, roll number and PC number as comments:
/************************************ * Name : Your name * * Roll Number : Your roll number * * PC Number : Number of your PC * * Assignment : Assignment number * * Exercise : Exercise number * ************************************/ Write your program here /***** End of program *****/
These information bind the print-outs to you. A print-out without these identifying comments will be ignored, that is, you deserve no credits for a print-out without your personal details.- In the command prompt (shell) do the following: (Assume that your program is named myprog.c.)
$ cc myprog.c # Compile your program $ ./a.out # Run your program, debug, etc. ... # Now you are sure that your program is correctly running # and you are getting the desired output. $ rm myprog.out myprog.prn # Delete old occurrences, if any (optional) $ ./a.out > myprog.out # Redirect output to the file myprog.out # If you want to take further runs, say with different input values, # append the new sessions of the runs to myprog.out. $ ./a.out >> myprog.out $ ./a.out >> myprog.out ... $ cat myprog.c myprog.out > myprog.prn # Generate the printer file $ cat myprog.prn # View the printer file to check that everything is okay $ lpr myprog.prn # Fire the print command- The values you input do not go to the output file (myprog.out) in the above procedure and hence will be absent in the final printout, unless you forcibly print them. Use printf after every scanf. For example:
printf("Input a positive integer : "); /* Prompt for the user */ scanf("%d",&n); /* Read user's input */ printf("%d\n",n); /* Echo the input value */- Check the printer file before firing the print-out: You may use cat as told above. You may use more or less for page-wise viewing of myprog.prn:
$ cat myprog.prn | less
Some commands during less viewing:You may even use an editor (like emacs or vi) to view the contents of myprog.prn. Do not alter the contents of the printer file.
Key Action [Space] Go to next page [Return] Scroll down one line [Up] Scroll up one line [Down] Scroll down one line g Go to the beginning G Go to the end q Quit less h Display help on less - Be absolutely certain that you are ready to take the printout, before firing the print command. Do not print multiple files for the same exercise.
- Follow the entire printing procedure described above for every exercise.
- Print only the input/output behavior of your program. Do not print any diagnostic message. You may use diagnostic messages to aid you in the debugging process. While taking the final printout, you must suppress all such messages.
What to do with the print-outs
You are supposed to preserve your print-outs. We need not correct your programs as soon as they are printed. We will give you the print-outs in the lab. You will be asked to produce those at a later time for evaluation.
Follow what the lab instructors say.