Header file:
stdlib.h
Synopsis:
long atol(const char *str);
Description:
It converts string str to a long value.
atol function C example:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
char str[100];
long val;
printf("Enter your input:");
fgets(str, 90, stdin);
str[strlen(str) - 1] = '\0';
val = atol(str);
printf("Converted long value: %ld\n", val);
return 0;
}
#include<stdlib.h>
#include<string.h>
int main() {
char str[100];
long val;
printf("Enter your input:");
fgets(str, 90, stdin);
str[strlen(str) - 1] = '\0';
val = atol(str);
printf("Converted long value: %ld\n", val);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input:2345678
Converted long value: 2345678
Enter your input:2345678
Converted long value: 2345678
No comments:
Post a Comment