How to convert string to numbers in C

2 Answers

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

int main() {
    char s[] = "4981";
    
	long int li = strtol(s, NULL, 10);
	
    printf("%ld\n", li);
	
    return 0;
}	

   
   
   
/*
run:
   
4981
   
*/

 



answered Jan 2, 2021 by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h>

int main() {
    char s[] = "3.14";
    
	float f = atof(s);
	
    printf("%f\n", f);
	
    return 0;
}	

   
   
   
/*
run:
   
3.140000

*/

 



answered Jan 2, 2021 by avibootz

Related questions

2 answers 122 views
1 answer 189 views
1 answer 198 views
1 answer 158 views
1 answer 157 views
2 answers 192 views
...