[ create a new paste ] login | about

Link: http://codepad.org/hLfp7dMJ    [ raw code | output | fork | 1 comment ]

joshua_cheek - C, pasted on Oct 21:
#include<stdio.h>

#define STR_SIZE 50

typedef struct
{
  char  name     [STR_SIZE];
  char  course   [STR_SIZE];
  char  phone    [STR_SIZE];
  char  address  [STR_SIZE];
} Student;

int main(){

  Student students[10] = {
    { "Karl" , "Economics"   , "123-456-7890" , "1234 N Platte" } ,
    { "Bill" , "Government"  , "234-567-8901" , "5243 E Perry"  } ,
    { "Will" , "Psychology"  , "345-678-9012" , "1734 S Prue"   } ,
    { "Fred" , "Philosophy"  , "456-789-0123" , "9239 W Pawn"   } ,
    { "Jill" , "Engineering" , "567-890-1234" , "4254 N Pike"   } ,
    { "Jane" , "Mathematics" , "678-901-2345" , "1337 E Pruitt" } ,
    { "Mark" , "Language"    , "789-012-3456" , "1661 S Prague" } ,
    { "Bert" , "Business"    , "890-123-4567" , "8761 W Pine"   } ,
    { "Zack" , "Biology"     , "901-234-5678" , "8971 N Plough" } ,
    { "Anna" , "Chemistry"   , "012-345-6789" , "5168 E Plume"  } 
  };
            
  int num_of_students = sizeof(students) / sizeof(Student) , i;
    
  for( i=0 ; i<num_of_students ; ++i )
  {
    printf( "%s is taking %s\n" , students[i].name , students[i].course );
    printf( "  They can be reached by phone at %s\n" , students[i].phone );
    printf( "  Or at the address %s\n\n" , students[i].address );
  }
    
  return 0;
}


Output:
Karl is taking Economics
  They can be reached by phone at 123-456-7890
  Or at the address 1234 N Platte

Bill is taking Government
  They can be reached by phone at 234-567-8901
  Or at the address 5243 E Perry

Will is taking Psychology
  They can be reached by phone at 345-678-9012
  Or at the address 1734 S Prue

Fred is taking Philosophy
  They can be reached by phone at 456-789-0123
  Or at the address 9239 W Pawn

Jill is taking Engineering
  They can be reached by phone at 567-890-1234
  Or at the address 4254 N Pike

Jane is taking Mathematics
  They can be reached by phone at 678-901-2345
  Or at the address 1337 E Pruitt

Mark is taking Language
  They can be reached by phone at 789-012-3456
  Or at the address 1661 S Prague

Bert is taking Business
  They can be reached by phone at 890-123-4567
  Or at the address 8761 W Pine

Zack is taking Biology
  They can be reached by phone at 901-234-5678
  Or at the address 8971 N Plough

Anna is taking Chemistry
  They can be reached by phone at 012-345-6789
  Or at the address 5168 E Plume



Create a new paste based on this one


Comments:
posted by joshua_cheek on Nov 15
Quick example of how to populate lots of information.
reply