home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / CataniaB / teach-act / esempi / Stringhe / stringToInt.c < prev   
C/C++ Source or Header  |  1999-03-11  |  271b  |  18 lines

  1. /* conversione da stringa ad intero positivo */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.   unsigned char c = '0';
  8.   int i = 0;
  9.  
  10.   printf("Inserire un intero: ");
  11.   while (c >= '0' && c <= '9')
  12.     {
  13.       i = 10 * i + c - '0';
  14.       c = getchar();
  15.     }
  16.   printf("\n%d\n",i);
  17. }
  18.