String-to-Number Conversions:
At times you will require converting the string representation of a number to a real numeric variable. For illustration, the string "123" can be transformed to a type int variable with the value 123. Three functions can be utilized to transform a string to a number. They are described in the following sections; their prototypes are in STDLIB.H.The atoi() Function:
The library function atoi() transforms a string to an integer. The prototype is:
int atoi(char *ptr);
The function atoi() transforms the string pointed to by ptr to an integer. Besides digits, the string can have leading white space and a + or -- sign. Conversion begins at the starting of the string and continues till an unconvertible character (for illustration, a letter or punctuation mark) is encountered. The resultant integer is returned to calling program.
When it finds no convertible characters, atoi() returns 0. The table lists shown below illustrate few examples.
=> String-to-number conversions with atoi():
The atol() Function:
The library function atol() works precisely identical to atoi(), apart from that it returns a type long. Function prototype is as:
long atol(char *ptr);The atof() Function:
The function atof() transforms a string to type double. The prototype is:
double atof(char *str);
The argument str points to string to be transformed. This string can include leading white space and a + or -- character. The number can have the digits 0 via 9, the decimal point, and the exponent indicator E or e. When there are no convertible characters, atof() returns 0. Table below lists some illustrations of using atof().=> String to number conversions with atof():
Character Test Functions:
The header file CTYPE.H comprises the prototypes for a number of functions which test characters, returning FALSE or TRUE depending on whether the character meets a certain condition. For illustration, is it a letter or a numeral? The isxxxx() functions are really macros, stated in CTYPE.H.
The isxxxx() macros all contain similar prototype:
int isxxxx(int ch);
In preceding line, ch is the character being tested. The return value is TRUE (that is, non-zero) if the condition is met or FALSE (or zero) if it isn't. The table below lists the complete set of isxxxx () macros.
=> The isxxxx() macros:
You can do lots of interesting things with the character-test macros. One case in point is the function get_int(), shown in Listing. This function inputs integer from stdin and returns it as a type int variable. The function skips over leading white space and returns 0 when the first non-space character is not a numeric character.
=> Employing the isxxxx() macros to implement a function which inputs an integer.
/* Using character test macros to create an integer */ /* input function. */ #include <stdio.h>#include <ctype.h> int get_int(void); main() { int x; x = get_int(); printf("You entered %d.\n", x); } int get_int(void) { int ch, i, sign = 1; while ( isspace(ch = getchar()) ); if (ch != `-' && ch != `+' && !isdigit(ch) && ch != EOF) { ungetc(ch, stdin); return 0; } /* If the first character is a minus sign, set*/ /* sign accordingly. */ if (ch == `-') sign = -1; /* If the first character was a plus or minus sign*/ /* get the next character. */ if (ch == `+' || ch == `-') ch = getchar(); /* Read characters until a nondigit is input. Assign*/ /* values, multiplied by proper power of 10, to i.*/ for (i = 0; isdigit(ch); ch = getchar() ) i = 10 * i + (ch - `0'); /* Make result negative if sign is negative.*/ i *= sign; /* If EOF was not encountered, a nondigit character*/ /* must have been read in, so unget it.*/ if (ch != EOF) ungetc(ch, stdin); /* Return the input value.*/ return i; }Output:
-100 You entered -100. abc3.145 You entered 0. 9 9 9 You entered 9. 2.5 You entered 2.Mathematical Functions:
The C standard library comprises a variety of functions which perform mathematical operations. The prototypes for mathematical functions are in the header file MATH.H. The math functions return a type double. For trigonometric functions, the angles are stated in radians. Keep in mind, one radian equivalents 57.296 degrees, and a full circle (360 degrees) has 2p radians.Trigonometric Functions:
Latest technology based Programming Languages Online Tutoring Assistance
Tutors, at the www.tutorsglobe.com, take pledge to provide full satisfaction and assurance in Programming Languages help via online tutoring. Students are getting 100% satisfaction by online tutors across the globe. Here you can get homework help for Programming Languages, project ideas and tutorials. We provide email based Programming Languages help. You can join us to ask queries 24x7 with live, experienced and qualified online tutors specialized in Programming Languages. Through Online Tutoring, you would be able to complete your homework or assignments at your home. Tutors at the TutorsGlobe are committed to provide the best quality online tutoring assistance for Programming Languages Homework help and assignment help services. They use their experience, as they have solved thousands of the Programming Languages assignments, which may help you to solve your complex issues of Programming Languages. TutorsGlobe assure for the best quality compliance to your homework. Compromise with quality is not in our dictionary. If we feel that we are not able to provide the homework help as per the deadline or given instruction by the student, we refund the money of the student without any delay.
Phase Transition tutorial all along with the key concepts of Phases of Matter, Phase Diagram, Co-exist Phases, Latent Heat, during Phase Transition, Kinds of Phase Transition, Lambda phase transition, Gibbs Function during Phase Transition, Clapeyron's Equation
www.tutorsglobe.com offers Benefits and Pitfalls of Use Cases homework help, assignment help, case study, writing homework help, online tutoring assistance by computer science tutors.
tutorsglobe.com significance of de-broglie waves assignment help-homework help by online de-broglie relation tutors
tutorsglobe.com heavy metals assignment help-homework help by online control of microorganisms tutors
ultrasound is cyclic sound pressure along with a frequency greater than the upper limit of human hearing.
Vinegar Analysis and Chromatography tutorial all along with the key concepts of Description of chromatography, Types of Chromatography, Gas chromatography, Chromatography Work, Theory of Thin Layer Chromatography, Experimental procedure
Application of the Coumarin and Chromones Ring tutorial all along with the key concepts of Warfarin, Racemic synthesis, Asymmetric hydrogenation, Hetero-Diels-Alder cycloaddition and Sodium Cromoglycate
theory and lecture notes of dc motors i all along with the key concepts of current carrying conductors in magnetic fields, force, current carrying loop in magnetic field, angle of motion, direction of current. tutorsglobe offers homework help, assignment help and tutor’s assistance on dc motors i.
www.tutorsglobe.com offers answering questions to income elasticity of demand, types of income elasticity, economics assignment help - homework help.
Disaccharides tutorial all along with the key concepts of How are Disaccharides formed and classified, physical properties of Disaccharide, Common Disaccharides, Maltose, Lactose and Sucrose
let the qualified tutors of literature review annotated bibliography assignment help fetch you notable grades at feasible prices.
While a company is registered with the Registrar of Companies, it has to be registered either as a public or as a private company.
ionic or salt-like hydrides tutorial all along with the key concepts of covalent hydride, metallic hydrides, electronegativity values, formation of hydrides, white crystalline solids
Rubber is acquired through vulcanizing raw rubber [natural/synthetic].Unimpregnated woven fabrics locate a number of limited uses in electrical insulation.
Measurement of water quality tutorial all along with the key concepts of Collection of Water Samples, Sampling of Rivers, Determination of water quality and Factors which Affect Water Quality
1960341
Questions Asked
3689
Tutors
1471744
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!