Skip to main content

Run a C program

Download the C compiler from here .download C compiler
and then run the following program than see the output.
The First Type & Run
Enter and compile the following program. If you get any errors, make sure you entered
the program correctly.
The usage for this program is print_it filename.ext, where filename.ext is the
source filename along with the extension. Note that this program adds line numbers to
the listing. (Don’t let this program’s length worry you; you’re not expected to understand
it yet. It’s included here to help you compare printouts of your programs with the ones
given in the book.)
LISTING T&R 1 print_it.c
1: /* print_it.c—This program prints a listing with line numbers! */
2: #include <stdlib.h>
3: #include <stdio.h>
4:
5: void do_heading(char *filename);
6:
7: int line = 0, page = 0;
8:
9: int main( int argv, char *argc[] )
10: {
11: char buffer[256];
12: FILE *fp;
13:
14: if( argv < 2 )
15: {
16: fprintf(stderr, “\nProper Usage is: “ );
17: fprintf(stderr, “\n\nprint_it filename.ext\n” );
18: return(1);
19: }
20:
21: if (( fp = fopen( argc[1], “r” )) == NULL )
22: {
23: fprintf( stderr, “Error opening file, %s!”, argc[1]);
24: return(1);
25: }
26:
27: page = 0;
28: line = 1;
29: do_heading( argc[1]);
30:
31: while( fgets( buffer, 256, fp ) != NULL )
32: {
33: if( line % 55 == 0 )
34: do_heading( argc[1] );
35:
26 Type & Run 1
Printing Your Listings 27
36: fprintf( stdprn, “%4d:\t%s”, line++, buffer );
37: }
38:
39: fprintf( stdprn, “\f” );
40: fclose(fp);
41: return 0;
42: }
43:
44: void do_heading( char *filename )
45: {
46: page++;
47:
48: if ( page > 1)
49: fprintf( stdprn, “\f” );
50:
51: fprintf( stdprn, “Page: %d, %s\n\n”, page, filename );
52: }
LISTING T&R 1 continued
This listing uses a value that is available within many PC compilers, but not
necessarily in all other compilers. Although stdout is an ANSI-defined value,
stdprn is not. You need to check your compiler for specifics on sending output
to the printer.
One option for getting around this is to change the stdprn statements to
stdout statements. This causes the output to go to the screen. Using your
operating system’s redirection features (or by piping if you’re using UNIX or
Linux), you should be able to redirect the output from the screen to the
printer.
Note
On Day 14, “Working with the Screen, Printer, and Keyboard,” you will learn more
about how this program works.

Comments

Popular posts from this blog

Hack the whatsapp

with this app you all can hack the whatsapp account of someone. enjoy hacking. with hacking i mean access to someone whatsapp without touching their phone. but first of all you need an access to their cell phone .  here is the app . note this may not be available in playstore. download from here and proceed step step as the app indicates.  size of app is less than 1 MB . thanks and keep visiting. see my others post also. WhatsApp Hack By: calmantez 4.5 /5 Using AIO Downloader Download whatever app you want for free. FILE PERMISSION DESCRIPTION AddThis Sharing Buttons Share to Facebook 203 Share to Twitter Share to Google+ Share to WhatsApp Share to More 2.2K File Name: WhatsApp Hack App Download Version: 1.0 (1) Price: Free APK Size: 0.19 MB Downloads: 500 Last Update Time: Jun 15, 2016 Min: Android 2.2.x (FROYO) Target: Android 4.4 (KITKAT) Screens: small, normal, large, xlarge Densities: 160, 240, 320, ...

Basics of python

Chapter 1 – Python Basics Read the author's other free Python books: Python Basics Lesson 2 - Expressions, Data Types, & Variables The Python programming language has a wide range of syntactical constructions, standard library functions, and interactive development environment features. Fortunately, you can ignore most of that; you just need to learn enough to write some handy little programs. You will, however, have to learn some basic programming concepts before you can do anything. Like a wizard-in-training, you might think these concepts seem arcane and tedious, but with some knowledge and practice, you’ll be able to command your computer like a magic wand to perform incredible feats. This chapter has a few examples that encourage you to type into the interactive shell, which lets you execute Python instructions one at a time and shows you the results instantly. Using the interactive shell is great for learning what ...