Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

C > Conversions Code Examples

Convert string to double: How to use atof: sines calculator

/* Convert string to double: How to use atof: sines calculator */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main () { double i, j; double pi=3.1415926535; char str[256]; printf ( "Enter degrees: " ); gets ( str ); i = atof ( str ); j = sin ( i * pi / 180 ); printf ( " sine of %f degrees = %f \n" , i, j ); return 0; }

Get string from stdin. Reads characters from the standard input (stdin) and stores them as a C string into str until a newline character or the end-of-file is reached. The newline character, if found, is not copied into str. A terminating null character is automatically appended after the characters copied to str. Notice that gets is quite different from fgets: not only gets uses stdin as source, but it does not include the ending newline character in the resulting string and does not allow to specify a maximum size for str (which can lead to buffer overflows).

Convert string to double. Parses the C string str, interpreting its content as a floating point number and returns its value as a double. The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals (see below), and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this function.

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:

Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with %), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers. printf format string refers to a control parameter used by a class of functions in the input/output libraries of C programming language. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data (such as a number) to characters. "printf" is the name of one of the main C output functions, and stands for "print formatted". printf format strings are complementary to scanf format strings, which provide formatted input (parsing). In both cases these provide simple functionality and fixed format compared to more sophisticated and flexible template engines or parsers,

Compute sine. Returns the sine of an angle of x radians. The C sin Function is a C Math Library Function, used to calculate the Trigonometry Sine value for the specified expression.

In C, the "main" function is treated the same as every function, it has a return type (and in some cases accepts inputs via parameters). The only difference is that the main function is "called" by the operating system when the user runs the program. Thus the main function is always the first code executed when a program starts. main() function is a user defined, body of the function is defined by the programmer or we can say main() is programmer/user implemented function, whose prototype is predefined in the compiler. Hence we can say that main() in c programming is user defined as well as predefined because it's prototype is predefined. main() is a system (compiler) declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.

Declare recursive function to find reverse of a number. Lets give a meaningful name to our function, say reverse(). C function computes reverse of number, hence it must accept an...

C program just print array in reversed order. It does not reverses the array. Here I am writing the first basic logic to reverse an array. It uses above approach to access array element in...

Lets find the length of the string using library function strlen(). A "string" is charracter array and a "Character Array" have character range between 0 to length-1. Thus we have position





C programming code to swap two numbers using XOR operator. Generally swaping two number requires three variables. Let's take look at procedure of swaping two numbers.



Adding two numbers using inline assembly language. Assembly language can be written in c. C supports assembly as well as higher language features so called "middle level...

What is function call by reference in C? When we call a function by passing the addresses of actual parameters then this way of calling the function is known as call by reference. In call