Posted By

RaghavSomani on 10/08/14


Tagged


Versions (?)

Convert String to integer array


 / Published in: C
 

To store large numbers into integer array by converting a string into interegr array.

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int* convert(char* c)
  5. {
  6. int len=strlen(c),i;
  7. int *a=(int*)malloc(len*sizeof(int));
  8. for(i=0;i<len;i++)
  9. a[i]=c[i]-48;
  10. return a;
  11. }
  12. int main(int argc, char const *argv[])
  13. {
  14. char c[100];
  15. scanf("%s",c);
  16. int *a=convert(c);
  17. free(a);
  18. return 0;
  19. }

Report this snippet  

You need to login to post a comment.