home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / discs / a / backup / !backup / h / backup next >
Encoding:
Text File  |  1991-10-12  |  1.2 KB  |  74 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define LINESIZE 255
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. char file_name[LINESIZE];
  9. char short_file_name[62];
  10. int filelength = 0;
  11. int file_attrib = 0;
  12. char current[] = "<backup$dir>.next";
  13. char file_path[] = "<backup$dir>.filepath";
  14. char *itoa(int n);
  15. void reverse(char *s);
  16. void backup(void);
  17. void changepath(void);
  18. int filename_len(char *file);
  19.  
  20. /***
  21.  itoa: convert int 'n' char returning this char pointer. .
  22. ***/
  23.  
  24. char *itoa(int n)
  25. {
  26. int sign,i,max = FALSE;
  27. char temp[20];
  28. char *s = temp;
  29.  
  30. for(i=0;i<20;i++)
  31.    temp[i] = '\0';
  32.  
  33. if ((sign = n) < 0){ /*** record sign ***/ 
  34.    if((n -1) > 0){   /*** if max negative integer ***/
  35.       ++n;
  36.       max = TRUE;
  37.       }
  38.    n = -n;
  39.    }
  40. do{ /*** generate digits in reverse order ***/
  41.    if(max == TRUE){
  42.       *s++ = n % 10 + '1';
  43.       max = FALSE;
  44.       }
  45.    else
  46.       *s++ = n % 10 + '0';
  47.    } while(( n /= 10) > 0);
  48. if( sign < 0)
  49.    *s++ = '-';
  50. reverse(temp);
  51. return temp;
  52. }
  53.  
  54. /***
  55. reverse: reverses the character string *s, (must be null terminated)
  56. ***/
  57. void reverse( char *s)
  58. {
  59. int i, mid;
  60. char *p, *t;
  61. p = t = s;
  62. while( *p != '\0')  
  63.    p++;
  64. p--;
  65. mid = ( (p - t) / 2 ) + 1;
  66. while( ( (t - s) + 1 ) <= mid ){
  67.    i = *t;
  68.    *t = *p;
  69.    *p = i;
  70.    p--,t++;
  71.    }
  72. }   
  73.  
  74.