Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to parse and validate a number in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
 
int main() {
    char s[30] = "948479843849854564654";
    char *endPtr;
     
    long long ll = strtoll(s, &endPtr, 10);

    if (errno == ERANGE) {
        printf("The number is too big for long long");
        return 1;
    }
     
    printf("%lld", ll);
     
    return 0;
}
 
 
/*
run:
 
The number is too big for long long
 
*/

 





answered Jan 3, 2021 by avibootz

Related questions

2 answers 97 views
97 views asked Jul 18, 2018 by avibootz
1 answer 54 views
54 views asked Jan 2, 2021 by avibootz
1 answer 71 views
71 views asked Dec 29, 2020 by avibootz
2 answers 94 views
2 answers 104 views
...