Question

Using C programming Using the supplied example code as a starting point, add 3 more conversions...

Using C programming

Using the supplied example code as a starting point, add 3 more conversions using strtod(). Make sure you change the output conversion for type double. Use the same input strings and base codes as the strtol() function example but notice how the numbers are now represented. Manipulate the width and precision as needed for a good presentation.  

Supplied code:

#include <stdio.h>

#include <string.h>

int main(void)

{

long num;

char* ptr;

num = strtol("12345 Decimal Constant: ", &ptr, 0);

printf("%s \t%ld\n", ptr, num);

num = strtol("11001 Binary Constant: ", &ptr, 2);

printf("%s \t%ld\n", ptr, num);

num = strtol("13572 123 Octal Constant: ", &ptr, 8);

printf("%s \t%ld\n", ptr, num);

//put your conversions here

return 0;

}//end main

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

#include <string.h>

int main(void)

{

long num;
double d;

char* ptr;

num = strtol("12345 Decimal Constant: ", &ptr, 0);

printf("%s \t%ld\n", ptr, num);

num = strtol("11001 Binary Constant: ", &ptr, 2);

printf("%s \t%ld\n", ptr, num);

num = strtol("13572 123 Octal Constant: ", &ptr, 8);

printf("%s \t%ld\n", ptr, num);

//put your conversions here

d = strtod("12345.0 Decimal Constant: ", &ptr, 0);

printf("%s \t%lf\n", ptr, d);

d = strtod("11001.0 Binary Constant: ", &ptr, 2);

printf("%s \t%lf\n", ptr, d);

d = strtod("13572 123 Octal Constant: ", &ptr, 8);

printf("%s \t%lf\n", ptr, d);

return 0;

}//end main

Note: Please comment if you have any doubts below บุ。u hau e anu/ doubts

Please up vote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
Using C programming Using the supplied example code as a starting point, add 3 more conversions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a functional ATM using the code base given in the example. You must use the...

    Create a functional ATM using the code base given in the example. You must use the routines provided in the code base example. Failure to follow the directions will result in an 'F' the example is down below! /* * @desc: Simple ATM machine * @duedate: 23-April-2019 * * * */ #include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> char menu(); char transaction_menu(); /* Verifies the Pin Entered match the PIN on record */ int validatePin(int); /* Verifies the funds...

  • can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf...

    can u please solve it in c++ format,,,, general format which is #include<stdio.h> .......printf and scanf format dont worry about the answers i have down Q3, What is the output of the program shown below and explain why. #include #include <stdio.h> <string.h> int main(void) ( char str[ 39764 int N strlen(str) int nunj for (int i-0; i t Nǐ.de+ printf(") num (str[] 'e); I/ digits range in the ASCII code is 48-57 if (nue > e) f 9 printf( Xdin,...

  • I need help fixing this code in C. It keeps giving me an error saying error:...

    I need help fixing this code in C. It keeps giving me an error saying error: ‘O_RDWD’ undeclared (first use in this function) if ((fd = open(fifo, O_RDWD)) < 0) note: each undeclared identifier is reported only once for each function it appears in. Please fix so it compiles properly. //************************************************************************************************************************************************** #include <fcntl.h> #include <stdio.h> #include <errno.h> #include<stdlib.h> #include <string.h> #include<unistd.h> #include <sys/stat.h> #include <sys/types.h> #define MSGSIZE 63 char *fifo = "fifo"; int main(int argc, char **argv){    int fd;...

  • Hello, I have my piece of C programming code and I have a pointer initialized to...

    Hello, I have my piece of C programming code and I have a pointer initialized to point to my array and I need help to display the contents of my array using a while loop or do-while loop. The stop condition should be when the pointer reaches '\0'. The code is below: #include <stdio.h> int main () {    char array[80]; printf("Enter a string: "); scanf("%[^\n]", &array); printf("%s\n", array); char * p;    p = array;         }

  • C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure...

    C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...

  • Could someone please help me with this C language code I'm confused as to why i'm...

    Could someone please help me with this C language code I'm confused as to why i'm getting an error every time I run it on command line if some could please help me as soon as possible. #include <stdio.h> #include <stdlib.h> int main() { char *ptr_two = (char *)malloc(sizeof(char)*50); printf("%p\n", ptr_two); ptr_two = "A constant string in C"; printf("%p\n", ptr_two); printf("%s\n", ptr_two); free(ptr_two); return 0; }

  • I NEED HELP FINDING THE BUG IN THIS CODE USING THE GDB #include #include <stdio.h> <string.h>...

    I NEED HELP FINDING THE BUG IN THIS CODE USING THE GDB #include #include <stdio.h> <string.h> Return the result of appending the characters in s2 to s1 Assumption: enough space has been allocated for sl to store the extra characters. char* append (char s1[ ], char s2[ ]) int sllenstrlen (s1); int s2lenstrlen (s2) int k; for (k=0; k<s21en; k++) { sl [kts11en] = s2 [k] ; return sl; int main () char strl [10]; char str2 [10]; while (1)...

  • getchar() redirect to input textfile in ASCI C programming. Hello, underneath is the code I did...

    getchar() redirect to input textfile in ASCI C programming. Hello, underneath is the code I did and it works. However, my professor is asking to use getchar() and have an input text file to redirect it. How would i do that on my code? Thank you for the help. #include <stdio.h> #include <string.h> int main() { char string[100]; int c = 0, Lcase[26] = {0}, x; int Ucase[26] = {0};    printf("Enter a string\n"); gets(string); while (string[c] != '\0') {...

  • A)Correct this code and explain what was corrected // C code - For Loop / Array...

    A)Correct this code and explain what was corrected // C code - For Loop / Array Population // This program will populate integers into an array, and then display those integers. // Developer: Johnson, William CMIS102 // Date: Mar 4, 2020 // Global constants #define INTLIMIT 10 #include <stdio.h> // This function will handle printing my name, class/section number, and the date void printStudentData() { char fullName[19] = "William J. Johnson"; char classNumber[9] = "CMIS 102"; char sectionNumber[5] = "4020";...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT