Infolinks In Text Ads

Invisibility Technology: Coming Soon Share

The race to make invisibility technology is on. Invisibility,may soon become a reality and through some interesting implementations, could actually serve as a useful feature in product design.

Monday, 1 August 2011

Information technology

The technology involved with the transmission and storage of information, especially the development, installation, implementation, and management of computer systems within companies, universities, and other organizations In the broadest sense, information technology refers to both the hardware and software that are used to store, retrieve, and manipulate information. At the lowest level you have the servers with an operating system. Installed...

14.6 Standard Library Functions

Standard Library FunctionsC's standard library contains many features and functions which we haven't seen. We've seen many of printf's formatting capabilities, but not all. Besides format specifier characters for a few types we haven't seen, you can also control the width, precision, justification (left or right) and a few other attributes of printf's format conversions. (In their full complexity, printf formats are about as elaborate and powerful as FORTRAN format statements.) A scanf function lets you do ``formatted input'' analogous to printf's formatted output. scanf reads from the standard...

14.5 C Preprocessor

C PreprocessorIf you're careful, it's possible (and can be useful) to use #include within a header file, so that you end up with ``nested header files.'' It's possible to use #define to define ``function-like'' macros that accept arguments; the expansion of the macro can therefore depend on the arguments it's ``invoked'' with. Two special preprocessing operators # and ## let you control the expansion of macro arguments in fancier ways. The preprocessor directive #if lets you conditionally include (or, with #else, conditionally not include) a section of code depending on some arbitrary compile-time...

14.4 Functions

FunctionsFunctions can't return arrays, and it's tricky to write a function as if it returns an array (perhaps by simulating the array with a pointer) because you have to be careful about allocating the memory that the returned pointer points to. The functions we've written have all accepted a well-defined, fixed number of arguments. printf accepts a variable number of arguments (depending on how many %signs there are in the format string) but we haven't seen how to declare and write functions that do thi...

14.3 Statements

StatementsThe switch statement allows you to jump to one of a number of numeric case labels depending on the value of an expression; it's more convenient than a longif/else chain. (However, you can use switch only when the expression is integral and all of the case labels are compile-time constants.) The do/while loop is a loop that tests its controlling expression at the bottom of the loop, so that the body of the loop always executes once even if the condition is initially false. (C's do/while loop is therefore like Pascal's repeat/until loop, while C's while loop...

14.2 Operators

OperatorsThe bitwise operators &, |, ^, and ~ operate on integers thought of as binary numbers or strings of bits. The & operator is bitwise AND, the | operator is bitwise OR, the ^ operator is bitwise exclusive-OR (XOR), and the ~ operator is a bitwise negation or complement. (&, |, and ^ are ``binary'' in that they take two operands; ~ is unary.) These operators let you work with the individual bits of a variable; one common use is to treat an integer as a set of single-bit flags. You might define the 3rd (2**2) bit as the ``verbose''...

14.1 Types and Declarations

Types and DeclarationsWe have not talked about the void, short int, and long double types. void is a type with no values, used as a placeholder to indicate functions that do not return values or that accept no arguments, and in the ``generic'' pointer type void * that can point to anything. short int is an integer type that might use less space than a plain int; long double is a floating-point type that might have even more range or precision than plain double. The char type and the various sizes of int also have ``unsigned'' versions, which are declared...

Chapter 14: What's Next?

Chapter 14: What's Next? This last handout contains a brief list of the significant topics in C which we have not covered, and which you'll want to investigate further if you want to know all of C. Types and Declarations Operators Statements Functions C Preprocessor Standard Library Functi...

Chapter 13: Reading the Command Line

Chapter 13: Reading the Command Line We've mentioned several times that a program is rarely useful if it does exactly the same thing every time you run it. Another way of giving a program some variable input to work on is by invoking it with command line arguments. (We should probably admit that command line user interfaces are a bit old-fashioned, and currently somewhat out of favor. If you've used Unix or MS-DOS, you know what a command line is, but if your experience is confined to the Macintosh or Microsoft Windows or some other Graphical User Interface, you may never have seen a command line. In fact, if you're learning C on a Mac or...

12.5 Example: Reading a Data File

Suppose you had a data file consisting of rows and columns of numbers: 1 2 34 5 6 78 9 10 112 Suppose you wanted to read these numbers into an array. (Actually, the array will be an array of arrays, or a ``multidimensional'' array; see section 4.1.2.) We can write code to do this by putting together several pieces: the fgetline function we just showed, and the getwords function from chapter 10. Assuming that the data file is named input.dat, the code would look like this:#define MAXLINE 100 #define MAXROWS 10 #define MAXCOLS 10 int array[MAXROWS][MAXCOLS]; char *filename = "input.dat"; FILE *ifp; char line[MAXLINE]; char...

12.4 Closing Files

Although you can open multiple files, there's a limit to how many you can have open at once. If your program will open many files in succession, you'll want to close each one as you're done with it; otherwise the standard I/O library could run out of the resources it uses to keep track of open files. Closing a file simply involves callingfclose with the file pointer as its argument: fclose(fp); Calling fclose arranges that (if the file was open for output) any last, buffered output is finally written to the file, and that those resources used by the operating system (and the C library) for this file are released. If you forget...

12.3 Predefined Streams

Besides the file pointers which we explicitly open by calling fopen, there are also three predefined streams. stdin is a constant file pointer corresponding to standard input, and stdout is a constant file pointer corresponding to standard output. Both of these can be used anywhere a file pointer is called for; for example, getchar()is the same as getc(stdin) and putchar(c) is the same as putc(c, stdout). The third predefined stream is stderr. Like stdout, stderr is typically connected to the screen by default. The difference is that stderr is not redirected...

12.2 I/O with File Pointers

For each of the I/O library functions we've been using so far, there's a companion function which accepts an additional file pointer argument telling it where to read from or write to. The companion function to printf is fprintf, and the file pointer argument comes first. To print a string to the output.dat file we opened in the previous section, we might call fprintf(ofp, "Hello, world!\n"); The companion function to getchar is getc, and the file pointer is its only argument. To read a character from the input.dat file we opened in the previous section, we might call int c; c = getc(ifp); The...

12.1 File Pointers and fopen

How will we specify that we want to access a particular data file? It would theoretically be possible to mention the name of a file each time it was desired to read from or write to it. But such an approach would have a number of drawbacks. Instead, the usual approach (and the one taken in C's stdio library) is that you mention the name of the file once, at the time you open it. Thereafter, you use some little token--in this case, the file pointer--which keeps track (both for your sake and the library's) of which file you're talking about. Whenever you want to read from or write to one of the files you're working with, you identify...

Chapter 12: Input and Output

Chapter 12: Input and Output So far, we've been calling printf to print formatted output to the ``standard output'' (wherever that is). We've also been calling getchar to read single characters from the ``standard input,'' and putchar to write single characters to the standard output. ``Standard input'' and ``standard output'' are two predefined I/O streamswhich are implicitly available to us. In this chapter we'll learn how to take control of input and output by opening our own streams, perhaps connected to data files, which we can read from and write to. 12.1 File Pointers and fopen 12.2 I/O with File...

11.4 Pointer Safety

At the beginning of the previous chapter, we said that the hard thing about pointers is not so much manipulating them as ensuring that the memory they point to is valid. When a pointer doesn't point where you think it does, if you inadvertently access or modify the memory it points to, you can damage other parts of your program, or (in some cases) other programs or the operating system itself! When we use pointers to simple variables, as in section 10.1, there's not much that can go wrong. When we use pointers into arrays, as in section 10.2, and begin moving the pointers around, we have to be more careful, to ensure that the roving pointers...

Twitter Delicious Facebook Digg Stumbleupon Favorites More