Using C Programing Compose Code Snippet Use Strtol Take Binary String Convert Long Storing Q37132544

Using C programing

Compose a code snippet that will use strtol() to take a binarystring and convert it to a long, storing it in an appropriatevariable.

Only write the syntax (code snippet) needed to perform thedirections above. You dont need to compose an entire program.


Solution


/*long int strtol(const char *nptr, char **endptr, intbase);

nptr Contains The Number in the Form Of String

endptr is reference object of type char* whose value is changed tonext character after the Number

*/

#include<stdlib.h>
#include<stdio.h>

int main()
{
   char binary[] = “101 001”;
   char *next;
   long out;

   out = strtol(binary,&next,0);

   printf(“%ldn”,out);
   printf(“Next substring Is : %s “,next);

   return 0;
}

/* output

./a.out
101
Next substring Is

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.