Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 50
  3. int getint(int *);
  4.  
  5.  
  6.  
  7. void main(void){
  8.     int i,n,array[SIZE];
  9.     printf("Egeszek tombbe olvasa es visszairasa cimeikkel egyutt!\n");
  10.     printf("Legfeljebb %d egesz szam van vagy EOF-ot megadva kevesebb!\n",SIZE);
  11.     printf("Adja meg az egesz szamokat!\n\n");
  12.     for(n=0;n<SIZE&&getint(&array[n])!=EOF;n++);
  13.     printf("\n\nA tombelemek cimei rendre:\n\n");
  14.     for(i=0;i<n;i++) printf("%10p",&array[i]);
  15.     printf("\n\nA tombelemek ertekei rendre:\n\n");
  16.     for(i=0;i<n;i++) printf("%10d",array[i]);
  17.     getch();
  18.  
  19. }
  20.  
  21. int getch(void);
  22. int ungetch(int);
  23. int getint(int *pn){ /*  A következő egész  bevolvasása*/
  24.     int c,sign=1;
  25.     //az elől lévő üres karakterek átlépése
  26.     while((c=getch())==' ' || c=='\n' || c=='\t' );
  27.     if(c=='+' || c=='-' ){
  28.         sign=(c=='+')?1:-1;
  29.         c=getch();
  30.     }
  31.         // A szám behozatala és konverziója
  32.     for(*pn=0;c>='0' && c<'9';c=getch()){
  33.         *pn=10**pn+c-'0';
  34.        
  35.     }
  36.     *pn*=sign;
  37.     if(c!=EOF) ungetch(c);
  38.     return c;
  39. }
  40. #define BUFSIZE 100
  41. char buf[BUFSIZE];
  42. int bufp=0;
  43. int getch(void){
  44.     return((bufp>0)?buf[--bufp]:getchar());
  45. }
  46. int ungetch(int c)
  47. {
  48.     if(bufp>=BUFSIZE){
  49.         printf("\n\tUngetch: Tul sok karakter!\n");
  50.         return EOF;
  51.     }else{
  52.         return buf[bufp++]=c;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement