How to convert a string to long in C

1 Answer

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

int main(void)
{
    char str[] = "09483751";

    long l = strtol(str, NULL, 10);

    printf("%ld\n", l);

    printf("%0*ld\n", (int)strlen(str), l);

    return 0;
}




/*
run:

9483751
09483751

*/

 



answered Jul 12, 2023 by avibootz

Related questions

1 answer 158 views
1 answer 194 views
1 answer 303 views
303 views asked Jun 20, 2021 by avibootz
1 answer 115 views
1 answer 178 views
178 views asked Jun 20, 2021 by avibootz
...