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 151 views
1 answer 188 views
1 answer 296 views
296 views asked Jun 20, 2021 by avibootz
1 answer 108 views
1 answer 164 views
164 views asked Jun 20, 2021 by avibootz
...