strtol c
// definition: long int strtol (const char* str, char** endptr, int base);
/* strtol example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* strtol */
int main ()
{
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
char * pEnd;
long int li1, li2, li3, li4;
li1 = strtol (szNumbers,&pEnd,10);
li2 = strtol (pEnd,&pEnd,16);
li3 = strtol (pEnd,&pEnd,2);
li4 = strtol (pEnd,NULL,0);
printf ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
return 0;
}
4
6
long strtol( const char * theString, char ** end, int base );
Thank you!
6
0
3.5
4
char *strncpy(char *dest, const char *src, size_t n)
Thank you!
4
0
4.14
7
# **strtol** | string to long integer | c library function
# EX.
# include <stdlib.h> // the library required to use strtol
int main() {
const char str[25] = " 2020 was garbage.";
char *endptr;
int base = 10;
long answer;
answer = strtol(str, &endptr, base);
printf("The converted long integer is %ld\n", answer);
return 0;
}
# ignores any whitespace at the beginning of the string and
# converts the next characters into a long integer.
# Stops when it comes across the first non-integer character.
long strtol(const char *str, char **endptr, int base)
# str − string to be converted.
# endptr − reference to an object of type char*, whose value is set
# to the next character in str after the numerical value.
# base − This is the base, which must be between 2 and 36 inclusive,
# or be the special value 0.
Thank you!
7
0
4
17
#include <stdio.h>
#include <stdlib.h>
int main () {
char str[30] = "2030300 This is test";
char *ptr;
long ret;
ret = strtol(str, &ptr, 10);
printf("The number(unsigned long integer) is %ld\n", ret);
printf("String part is |%s|", ptr);
return(0);
}
Thank you!
17
0
4
10
int my_strlen(char *str) {
int i = -1;
while (str && str[++i]);
return (i);
}
Thank you!
10
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
-
-
-
-
-
-