Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: C++  |  size: 1.42 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <malloc.h>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. template<class T>
  8.             class ChainNode{
  9.             friend class Chain;
  10.                 private:
  11.                         T data;
  12.                         ChainNode<T> *link;
  13.         };
  14.  
  15. template<class T>
  16.                 class Chain {
  17.                 public:
  18.                         Chain(){first = 0 ;}
  19.                 private:
  20.                         ChainNode<T> *first;//pointer to first Node
  21.                 };
  22.  
  23.  
  24.  
  25.     struct Pelates{
  26.                      
  27.             //au3ontas ari8mos pelatwn
  28.                         ChainNode<int> *link ;//periexei tn sundesmo gia tn eisagwgh stn lista
  29.                     char onomaPel[];//oi pelates se unsized array
  30.     };
  31.      
  32.     int main(){
  33.        
  34.                         Pelates *StrPtr;//orizw enan pointer ap tn klassh pelates
  35.                     //autos o pointer deixnei stn prwto kombo ts alusidas
  36.                         Pelates *ptr;
  37.                         char pel[40];
  38.  
  39.                         printf("enter code:");
  40.                         gets(pel);
  41.                         //xwros mnhmhs g tstruct, t onoma kai terminating null
  42.                         ptr = (Pelates *)malloc( sizeof( struct Pelates)+ strlen( pel ) + 1 );
  43.          
  44.                         strcpy( ptr->onomaPel, pel);//ekxwrei t string st onoma pelath
  45.                         return 0;
  46.         }
  47.  
  48.        
  49.  
  50. /*      struct PERSON
  51. {
  52.    unsigned number;
  53.    char name[];   // Unsized array
  54. };
  55.  
  56. int main()
  57. {
  58.    PERSON *ptr;
  59.    char who[40];
  60.  
  61.    printf( "Enter name: " );
  62.    gets( who );
  63.    // Allocate space for structure, name, and terminating null
  64.    ptr = (PERSON *)malloc( sizeof( struct PERSON ) + strlen( who ) + 1 );
  65.  
  66.    // Copy the string to the name member
  67.    strcpy( ptr->name, who );
  68. }*/