Alex9090

Untitled

Feb 7th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<limits.h>
  4. #include<errno.h>
  5. #include<string.h>
  6. #include<ctype.h>
  7. void oglindit(long numar){
  8.  
  9. int aux = 0, c = 0;
  10.  
  11. if(numar == 0){
  12. fprintf(stderr, " Oglinditul este 0.\n");
  13. }
  14.  
  15. int copy = numar, copyaux;
  16. int nra=0, nraux=0;
  17.  
  18. while (numar){
  19. aux = aux*10 + numar%10;
  20. numar = numar/10;
  21. nra++;
  22. }
  23.  
  24. copyaux = aux;
  25.  
  26. while (aux){
  27. aux = aux/10;
  28. nraux++;
  29. }
  30. printf(" Oglindit %d ", copyaux);
  31.  
  32. }
  33. int main(int argc, char *argv[])
  34. {
  35. int a;
  36. char *endptr;
  37.  
  38. if (argc != 2)
  39. {
  40. fprintf(stderr, "Utilizare: %s numar\n", argv[0]);
  41. exit(EXIT_FAILURE);
  42. }
  43.  
  44. int val = strtol(argv[1], &endptr, 10);
  45. if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))|| (errno != 0 && val == 0)) {
  46. perror("strtol");
  47. exit(EXIT_FAILURE);
  48. }
  49. if (*endptr != '\0' || strcmp(argv[1], "") == 0 ){
  50. fprintf(stderr, "%s invalid", argv[1]);
  51. exit(EXIT_FAILURE);
  52. }
  53. if(strncmp (argv[1], "0", 1) == 0){
  54. fprintf(stderr, "Invalid, incepe cu 0");
  55. exit(EXIT_FAILURE);
  56. }
  57.  
  58. if (strcmp (argv[1], "") == 0 || (*endptr != '\0'))
  59. {
  60. fprintf(stderr, " Data de intrare invalida! %s \n", argv[1]);
  61. exit(EXIT_FAILURE);
  62. }
  63.  
  64.  
  65.  
  66.  
  67. a = val;
  68.  
  69. oglindit(a);
  70.  
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment