Knowee
Questions
Features
Study Tools

The following function is an imitation of the atof() function given in KnR  in section 4.2Complete it. Do not use space in any answer.double atof(char *str) {    double whole = 0.0, power = Answer ;    int sign;    while(Answer && (*str == ' ' || *str == '\t'))        str++;    sign = (*str == '-' ? -1 : Answer );    (*str == '-' || *str == '+') ? Answer : NULL;        while(*str && (*str >= Answer && *str <= Answer ))        whole = whole * Answer + (Answer - Answer );    *str == Answer ? str++: NULL;    while(*str && (*str >= Answer && *str <= Answer )) {        whole = Answer * 10.0 + (Answer - '0');        power *= 10.0;    }       return sign * whole / power;}

Question

The following function is an imitation of the atof() function given in KnR  in section 4.2Complete it. Do not use space in any answer.double atof(char *str) {    double whole = 0.0, power = Answer ;    int sign;    while(Answer && (*str == ' ' || *str == '\t'))        str++;    sign = (*str == '-' ? -1 : Answer );    (*str == '-' || *str == '+') ? Answer : NULL;        while(*str && (*str >= Answer && *str <= Answer ))        whole = whole * Answer + (Answer - Answer );    *str == Answer ? str++: NULL;    while(*str && (*str >= Answer && *str <= Answer )) {        whole = Answer * 10.0 + (Answer - '0');        power *= 10.0;    }       return sign * whole / power;}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the completed function:

double atof(char *str) {
    double whole = 0.0, power = 1.0;
    int sign;
    while(*str && (*str == ' ' || *str == '\t'))
        str++;
    sign =

Similar Questions

In C++, atof () function is used to convert ________.

at will be the output of the following code?1234567#include <stdio.h> int main() { for(int k = 0; k < 5; k++) { printf("%d ", k * k (k + k)); } return 0; }Marks : 1Negative Marks : 0Answer here0 1 4 9 160 2 4 6 81 4 9 16 25Compile time error

#ifndef main.h#define main.h#include <stddef.h>int _putchar(char c);int _islower(int c);int _isalpha(int c);int _abs(int n);int _isupper(int c);int _isdigit(int c);int _strlen(char *s);void _puts(char *s);char *_strcpy(char *dest, char *src);int _atoi(char *s);char *_strcat(char *dest, char *src);char *_strncat(char *dest, char *src, int n);char *_strncpy(char *dest, char *src, int n);int _strcmp(char *s1, char *s2);char *_memset(char *s, char b, unsigned int n);char *_memcpy(char *dest, char *src, unsigned int n);char *_strchr(char *s, char c);unsigned int _strspn(char *s, char *accept);char *_strpbrk(char *s, char *accept);char *_strstr(char *haystack, char *needle);#endif main.h~ ~ ~

Mark statements as T/F.True False int *p, i;char *cp, c;p = &i;cp = (char *)p;cp[2] = 'x';The last line of the above code modifies the variable i int *p; double *dp;sizeof(p) is 4 bytes while sizeof(dp) is 8 bytes. int *p;p[1] means *(p + 1) int *p; double *dp;p = p + 1 advances p by sizeof(int) bytes

What is the output for the following code?123456789101112131415#include <stdio.h> int main() { int n = 5; int arr[5] = {1, 2, 3, 4, 5}; int e = 0; for (int i = 0; i < n; ++i) { if (arr[i] % 2 == 0) { ++e; } } double p = (double)e / n * 100; printf("%.2f", p); return 0;}

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.