[Read more…] about C Program square and cube of first n natural numbers
C program to calculate tax, given the following conditions
In this tutorial, we can learn C program to calculate tax. In this c program, we enter a number and calculate tax with the given following conditions. [Read more…] about C program to calculate tax, given the following conditions
Conditional Directives in C
The conditional directives are meant to control the compilation process. By using them we may conditionally include certain statements of the program for compilation. If the condition is not met the statements are not included. These directives also help us not to include duplicate files in the program and cause error. For example, see the following code: [Read more…] about Conditional Directives in C
Nesting of Macros in C
A macro may be used in the definition of another macro as illustrated below. [Read more…] about Nesting of Macros in C
Preprocessor Directive #define
Macros may also be created by #define. Here the identifier can have parameters but types of parameters are not mentioned. [Read more…] about Preprocessor Directive #define
Preprocessor operator ##.
The token # single in its own line is null directive. It is simply neglected by compiler. Thus, if the code is simply as given below, it is neglected by the compiler. [Read more…] about Preprocessor operator ##.
#define and #undef preprocessor directives
The directive #define is used to create symbolic constants and macros (small function type entities). The directive #define may be used in the following manner: [Read more…] about #define and #undef preprocessor directives
Function strftime () in C
The syntax of the function is as follows:
size_t strftime(char* s, size_t maxsize, const char* format, const struct tm * Tmptr);
The function strftime () formats the broken-down time tm into an array pointed to by s according to the specified formatting string pointed to by format. The size of array is limited by maxsize. The formatting string consists of 0 or more conversion Specifiers and ordinary characters. The ordinary characters placed in the formatting string are copied into s without any conversion. Each specifier consists of a percent character(%) followed by a character that determines the action of conversion specifier. Some conversion Specifiers may have an additional modifier character E or 0 placed between% symbol and the conversion specifier character. The strftime() function returns the number of characters placed in the arrays, not including the terminating Null character.
Illustrates application of function strftime (). [Read more…] about Function strftime () in C
Function asctime () in C
The syntax of the function asctime () is written as follows: [Read more…] about Function asctime () in C
Function ctime () in C
The function prototype of ctime () is written in the following manner: [Read more…] about Function ctime () in C
Function localtime () in C
The function localtime () converts the calendar time, i.e., the output of function time (), into a broken-down time expressed as local time, and returns the pointer to broken-down time. If the conversion into local time fails, the function returns NULL pointer. The prototype of the function is written in the following manner: [Read more…] about Function localtime () in C
Function mktime () in C
The prototype of the function is written as given below, [Read more…] about Function mktime () in C
Function difftime () in C
The function difftime ()returns the difference between two calendar times in seconds, i.e., number of seconds elapsed between two calendar times time2 and time]. The calendar time represents the time elapsed since 00:00:00 hours 01 January 1970, GMT. The function returns the difference in seconds as a double number. The function prototype is written as follows: [Read more…] about Function difftime () in C
Function time () in C
The function time () returns the current calendar time, i.e., the number of seconds elapsed since 00:00:00 hour January 1, 1970 GMT (or gmt are used alternatively) up to the execution of the function. The function prototype is written as follows: [Read more…] about Function time () in C
Function clock () in C
The clock function is used to determine the processor time in executing a program or part of a program. The header file <time.h> should be included in the program for its application. The function prototype is given below. [Read more…] about Function clock () in C
Error-Handling functions in C
Function clearerr () [Read more…] about Error-Handling functions in C
Function putw()and getw() in C
Function putw() [Read more…] about Function putw()and getw() in C
Appending Text in a File in C
Appending to a file means adding at the end of the file while keeping the previous contents of the file intact. For this the file open mode is “a”. Program illustrates appending a file. [Read more…] about Appending Text in a File in C
Function ungetc() in C
The function prototype is written in the following manner: [Read more…] about Function ungetc() in C
Function remove() in C
The prototype of this function is given below. [Read more…] about Function remove() in C
Function rename () in C
This function is used to change the name of file. Its prototype may be written as given below. [Read more…] about Function rename () in C
Function freopen () in C
This function may be used for opening a file in different modes. The function prototype may be written in the following manner: [Read more…] about Function freopen () in C
void Pointers in C
The assignment operator (=) may be used on pointers of the same type. However, if the types of pointers (types of variables to which they point) are not same then we will have to do type casting of one of these to the type of the other to use assignment operator. However, the void pointer (void * ) can represent any pointer type. Thus, any type of pointer may be assigned to a void pointer. However, the reverse is not valid. A void pointer cannot be assigned to any other type of pointer without first converting the void pointer to that type. [Read more…] about void Pointers in C
typedef for Pointers to Functions in C
We may make use of typedef for declaring pointers to functions. Examine the following code: [Read more…] about typedef for Pointers to Functions in C
Pointer to Functions as Parameter in C
A function may have another function as one of its parameters besides having parameters of other data types. A function is a derived type object; its type is derived from the type of data it returns. Like arrays, the name of a function also holds the address of the function. [Read more…] about Pointer to Functions as Parameter in C
Pointer to Three-Dimensional Arrays in C
If elements of an array are two-dimensional arrays, the array is called a three-dimensional array. Therefore, a three-dimensional array may be considered as an array of matrices. Let Arm be a 3-dimensional array or an array of matrices. The declaration of pointer and its initialization is carried out as given below. [Read more…] about Pointer to Three-Dimensional Arrays in C
Manipulation of Complex Numbers by Structures
A complex number is also a multivalue object. It consists of two parts: real part and imaginary part. The imaginary part carries symbol i which is equal to √-1 . A complete number is written as sum of the real part and the imaginary part as shown below. [Read more…] about Manipulation of Complex Numbers by Structures
Vectors with Structures in C
Since structures are multivalue, multitype data objects, they can be considered to form a useful tool in manipulation of quantities such as vectors, complex variables, etc. For this we define functions of the type struct, i.e., the return value of the function is a structure. The function may have arguments of type struct besides other arguments. Let us define a structure with three components of vector as its data members as shown below. [Read more…] about Vectors with Structures in C
Sorting of Structures in C
When structures are used to keep record of employees, students, and so on, we would need to sort them according to some criterion. For employees, it may be according to alphabetical order, designation, or pay. [Read more…] about Sorting of Structures in C
C Program to Structure as a Parameter of Functions
Program provides an illustration of a function with structure as one of its parameter. The function calculates and returns the magnitude of a vector which is an instance of structure defined to hold the three components of a vector as its data members. The structure is declared as below. [Read more…] about C Program to Structure as a Parameter of Functions