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