ANAND ENGINEERING COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 1

UNIT V Macros A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. Example #define max(x,y) (a>b)?:a:b; File Handling in C We frequently use files for storing information which can be processed by our programs. In order to store information permanently and retrieve it we need to use files. Files are not only used for data. Our programs are also stored in files. You declare the file pointer variable as follows: FILE *fp; The header file file to be included for using files. fp = fopen( “prog.c”, “r”) ;

opens a file called prog.c for reading and associates the file

pointer fp with the file. If the file cannot be opened, it returns a NULL pointer. Example fp = fopen (filename, “r”) ; if ( fp == NULL) {

printf(“Cannot open %s for reading \n”, filename ); exit(1) ; /*Terminate program: Commit suicide !!*/

} File opening modes r

open for reading.

w

open for writing.

a

open for appending.

r+

open for both reading and writing. The stream will be positioned at the beginning of

the file. w+

open for both reading and writing. The stream will be created if it does not exist, and

will be truncated if it does exist. a+

open for both reading and writing. The stream will be positioned at the end of the

existing file content. rb

open for reading. The 'b' indicates binary data (as opposed to text); by default.

wb

open for writing. The 'b' indicates binary data.

ab

open for appending. The 'b' indicates binary data

c = getc(fp);

reads the next character from the file referenced by fp and the statement

putc(c,fp);

writes the character c into file referenced by fp.

ANAND ENGINEERING COLLEGE

fclose(fp);

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 2

is used to close the file i.e. indicate that we are finished processing this file.

fprintf() #include int fprintf( FILE *stream, const char *format, ... ); The fprintf() function sends information (the arguments) according to the specified format to the file indicated by stream. fprintf() works just like |printf()| as far as the format goes. The return value of fprintf() is the number of characters outputted, or a negative number if an error occurs. Example: char name[20] = "Mary"; FILE *out; out = fopen( "output.txt", "w" ); if( out != NULL ) fprintf( out, "Hello %s\n", name ); fscanf() int fscanf( FILE *stream, const char *format, ... ); The function fscanf() reads data from the given file stream in a manner exactly like scanf()|. The return value of fscanf() is the number of variables that are actually assigned values, or EOF if no assignments could be made. feof(); returns true of end of file has been encounterd, false otherwise fread() int fread( void *buffer, size_t size, size_t num, FILE *stream ); The function fread() reads num number of objects and places them into the array pointed to by buffer. fwrite() int fwrite( const void *buffer, size_t size, size_t count, FILE *stream ); The fwrite() function writes, from the array buffer, count objects of size size to stream. The return value is the number of objects written. String Handling in C strcpy( char *s1, char *s2) copies the string s2 into the character array s1. strcat( char *s1, char *s2) appends the string s2 to the end of character array s1. The first character from s2 overwrites the '\0' of s1. The value of s1 is returned. strcmp(char *s1, char *s2) compares the string s1 to the string s2. The function returns 0 if they are the same, a number < 0 if s1 < s2, a number > 0 if s1 > s2. stricmp( const char *s1, const char *s2, size_t n) compares characters of the

ANAND ENGINEERING COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 3

string s1 to the string s2,, ignoring the case. The function returns 0 if they are the same, a number < 0 ifs1 < s2 s2, a number > 0 if s1 > s2. strlen(char *s) determines the length of the string s. Returns the number of characters in the string before the '\0'. STACK A stack is a data structure where stack items can only be added or removed from the end of the stack. LIFO (Last In First Out). Stack Declaration int tos, stack[SIZE]; PUSH - Adding to stack

POP-Deleting from stack

void push(int data)

int pop(void)

{

{ if(tos == SIZE)) {

if(tos < 0) {

printf("Stack Overflow.\n");

printf("Stack Underflow.\n");

exit(1);

exit(1);

}

}

stack[tos]=data;

tos--;

tos++;

return *(stack[tos]);

}

}

LINKED LISTS A linked list is comprised of a series of nodes, each node containing a data element, and a pointer to the next node, eg, A structure which contains a data element and a pointer to the next node is created by, struct list { int value; struct list *next;

};

This defines a new data structure called list), which contains two members. The first is i an integer called value. The second is called next, which is a pointer to another list structure (or node). Declare linked list pointers struct list n1, n2; The next pointer of structure n1 may be set to point to the n2 structure by n1.next = &n2; which creates a link between the two structures. Mathematical Functions There are more than twenty mathematical functions declared in . here are some of the more frequently used. Each takes one or two double arguments and returns a double.

ANAND ENGINEERING COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 4

sin(x)

sine of x, x in radians

cos(x)

cosine of x. x in radians

exp(x)

exponential function

log(x)

natural (base e) logarithm of x (x >0)

pow(x,y)

x raised to power of y

sqrt (x)

square root of x (x>=0)

fabs(x)

absolute value of x

Conditional Compilation/Conditional Inclusion ·

It is possible to control preprocessing itself with conditional statements

·

These statements are evaluated during preprocessing.

·

This provides a way to include code selectively, depending on the value of conditions evaluated during compilation.

·

It allows the selection of lines of source code to be compiled and those to be ignored.

·

Lines of source code that may be sometimes desired in the program and other times not, are surrounded by #ifdef, #endif directive pairs as follows:

#ifdef DEBUG printf("x = %d, y = %f\n", x, y); ... #endif The #ifdef directive specifies that if DEBUG exists as a defined macro, i.e. is defined by means of a #define directive, then the statements between the #ifdef directive and the #endif directive are retained in the source file passed to the compiler. If DEBUG does not exist as a macro, then these statements are not passed on to the compiler. Thus to ``turn on'' debugging statements, we simply include a definition: #define DEBUG 1 in the source file; and to ``turn off'' debug we remove (or comment) the definition. The syntax is: # [ # ] [ # ] # #

ANAND ENGINEERING COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 5

If the if-part is True, then all the statements until the next , or are compiled; otherwise, if the is present, the statements between the and the are compiled. L-Values and R-Values Expressions in C++ can evaluate to l-values or r-values. L-values are expressions that evaluate to a type other than void and that designate a variable. L-values appear on the left side of an assignment statement (hence the "l" in l-value). Variables that would normally be l-values can be made non-modifiable by using the const keyword; these cannot appear on the left of an assignment statement. Reference types are always l-values. The term r-value is sometimes used to describe the value of an expression and to distinguish it from an l-value. All l-values are r-values but not all r-values are l-values. Some examples of correct and incorrect usages are: int main() { int i, j, *p; i = 7; // OK variable name is an l-value. 7 = i; // C2106 constant is an r-value. j * 4 = 7; // C2106 expression j * 4 yields an r-value. *p = i; // OK a dereferenced pointer is an l-value. const int ci = 7; ci = 9; // C3892 ci is a nonmodifiable l-value ((i < 3) ? i : j) = 7; // OK conditional operator returns l-value. } Command-Line Arguments Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux. Function main() can accept two arguments: 1. one argument is number of command line arguments, and 2. second argument is a full list of all of the command line arguments. The full declaration of main looks like this: int main ( int argc, char *argv[] ) argc is the argument count – number of arguments passed from the command line argv[0] is the name of the program, argv[1] is the first argument argv[0] is the second argument and so on. Example: write a function that takes the name of a file and outputs the entire text onto the screen. #include int main ( int argc, char *argv[] )

ANAND ENGINEERING COLLEGE

DEPARTMENT OF INFORMATION TECHNOLOGY VINAY KUMAR SINGH 6

{ if ( argc != 2 ) /* argc should be 2 for correct execution */ {

printf( "usage: %s filename", argv[0] );

} else {

FILE *file = fopen( argv[1], "r" ); if ( file == 0 ) {

printf( "Could not open file\n" );

} else {

int x; while ( ( x = fgetc( file ) ) != EOF ) {

printf( "%c", x );

} } fclose( file ); } }

UNIT V Macros A macro is a fragment of code which ...

UNIT V. Macros. A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. Example. #define max(x,y) (a>b)?:a:b;. File Handling in C. We frequently use files for storing information which can be processed by our programs. In order to store ...

154KB Sizes 1 Downloads 144 Views

Recommend Documents

Notification of discontinuation of a paediatric development which is ...
Reasanz. Latest Decision number(s):. 1) P/0292/2016. 2) P/. 3) P/. 4) P/. Corresponding PIP number(s): 1) EMEA-001168-PIP01-11-M03. 2) EMEA- 3) EMEA-. 4) EMEA-. Please note that development of the medicinal product ... manufacturing / quality problem

Notification of discontinuation of a paediatric development which is ...
Actives substances(s): vorapaxar sulphate. Invented name: Zontivity. Latest Decision number(s):. 1) P/0131/2016. 2) P/. 3) P/. 4) P/. Corresponding PIP number(s): 1) EMEA-000778-PIP02-12-M01. 2) EMEA- 3) EMEA-. 4) EMEA- ... manufacturing / quality pr

Dynamic Estimation of Intermediate Fragment Size in a Distributed ...
Student, Department of Computer Science & Engineering, Guru Nanak Dev University Amritsar, Punjab, India. Dr. Rajinder Singh Virk. Department of Computer ...

1.Which command is used to remove a file? 2.Which ...
WISHYOUONLINE.BLOGSPOT.COM. A.Text Editor. B.Assembler. C.Linker. D.Loader*. Ans:D. 6.When was Apple Macintosh II micro computer introduced in the.

a/ ?\v 'a
nection therewith to give access to the lockers. The temperature in the locker room of frozen food lockers is usually maintained at about zero degrees F. and itis ...

1.SCSI stands for: 2.Which of the following is a logical extension of ...
The GSM network is divided into the following three major systems: Ans:SS .... congestion: ... AJAX is based on internet standards,and uses a combination of:.

Dynamic Estimation of Intermediate Fragment Size in a Distributed ...
database query optimization process. In this process sub-queries are allocated to different nodes in a computer network. Query is divided into sub queries and then sub query allocation is performed optimally. Cost depends on the size of intermediate

Unit V Review.pdf
300 Sensational journalism intended to sell papers with little regard for the truth. 400 The addition of new territory to an existing nation. 500 A belief that nations ...

PGA Tour, Inc. v. Martin - Is Golf a Sport?
May 29, 2001 - viduals with disabilities continue to be a serious and pervasive social problem. ..... the basis of race, color, religion, or national origin. §2000a(a). In Daniel v. Paul, 395 ..... Davis, Magee Gets Ace on Par-4,. Ariz. Republic, Jan

PGA Tour, Inc. v. Martin - Is Golf a Sport?
half of them make it to the second stage, which also in- cludes 72 holes. ... App. 125. 4 The PGA TOUR hard card provides: “Players shall walk at all times during a .... “A. Oh, there's no doubt, again, but that, that fatigue does play a big part

2.In which district is 'Ponmudi Dam'situated?
MORE FILES DOWNLOAD VISIT ​WWW.WISHYOUONLINE. ... 3.Which Road is the first Rubberised Road in Kerala? A.Kottayam-Kumali*. B.Kottayam-Erumelly.

A SECTOR-WISE JPEG DATA FRAGMENT ...
A SECTOR-WISE JPEG DATA FRAGMENT CLASSIFICATION METHOD BASED ON IMAGE. CONTENT ANALYSIS. Yu Chen and Vrizlynn L. L. Thing. Institute ...

"Knowledge is that which ..." "Knowledge is that ... -
what the Messenger [. ىلص. ملس و هيلع الله. , may Allah exalt his mention and render him and his message safe from every derogatory thing ] came with".

WHICH THOUSAND WORDS ARE WORTH A PICTURE ...
On the contrary, content-based video retrieval (e.g. [2]) employs technologies ... example, A user with information need, “find shots of one or more roads with lots ...

A Fragment Based Scale Adaptive Tracker with Partial ...
with maximum histogram similarity with the template fragments contribute ..... [3] E. Maggio and A. Cavallaro, “Multi-part target representation for color tracking ...

A Fragment Based Scale Adaptive Tracker with Partial ...
In [2], a multi-part representation is used to track ice-hockey players, dividing the rectangular box which bounds the target into two non-overlapping areas corresponding to the shirt and trousers of each player. A similar three part based approach i

SILE comes with a number of packages which provide ... - GitHub
SILE comes with a number of packages which provide additional functionality. A box: here. Test underlining several words.

1499608745011-which-generate-a-honest-total-of-views-next ...
Page 2 of 2. Page 2 of 2. 1499608745011-which-generate-a-honest-total-of-views ... ook-appliance-marketing-concert-party-production.pdf.

Seawalls and Stilts: A Quantitative Macro Study of ...
May 18, 2018 - In the low risk localities, adaptation capital is zero and thus ..... less than 10 percent of middle class assets.11 Furthermore, many of these stock ...

UNIT V APPLICATION LAYER.pdf
Download. Connect more apps... Try one of the apps below to open or edit this item. UNIT V APPLICATION LAYER.pdf. UNIT V APPLICATION LAYER.pdf. Open.

Udhaar and Swarmy v. Republic of Hind 1. Republic of Hind is a ...
Jun 21, 2015 - Mahant Sadyoga Guru (“MSG”) was a world-renowned and globally popular ... Though MSG was very popular and had many disciples and.

Udhaar and Swarmy v. Republic of Hind 1. Republic of Hind is a ...
Jun 21, 2015 - Om-Chai issued a Notification (“Yoga Day Notification”) announcing the programs for World Yoga Day Celebrations which included compulsory ...

An Ancient Peace There is a silence into which the ... -
An Ancient Peace. There is a silence into which the world cannot intrude. There is an ancient peace you carry in your heart and have not lost. There is a love you ...