int main(int argc, char *argv[]) {

	//make 2 people structures
	struct Person *joe = Person_create("Joe Alex", 32, 64, 140);

	struct Person *frank = Person_create("Frank Blank", 20, 72, 180);
	
	//print them out and where they are in memory
	printf("Joe is at memory location %p:\n", &joe);
	Person_print(&joe);
	
	printf("Frank is at memory location %p:\n", frank);
	Person_print(frank);

	//advance everyone's age by 20 years and print again
	(*joe).age += 20;
	(*joe).height -= 2;
	(*joe).weight += 40;
	Person_print(joe);

	frank->age += 20;
	frank->weight += 20;
	Person_print(frank);

	//destroy them both so we clean up.
	Person_destroy(joe);
	Person_destroy(frank);

	return 0;
}
int main(int argc, char *argv[])
{
  //Make two people structures
  struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
  struct Person *frank = Person_create("Frank Blank", 20, 72, 180);
  
  //Print them out and where they are in memory
  printf("Joe is at memory location: %p\n", joe);
  Person_print(joe);

  printf("Frank is at memory location: %p\n", frank);
  Person_print(frank);


  frank->age += 20;
  joe->height -= 2;
  joe->weight += 40;
  Person_print(joe);

  frank->age += 20;
  frank->weight += 20;
  Person_print(frank);

  // Destroy them both so we can clean up
  Person_destroy(joe);
  Person_destroy(frank);
  /* makes the program abort(As long as our make file uses the -g option with the CFLAGS): */
//  Person_destroy(NULL);

  return 0;
}
示例#3
0
文件: ex16.c 项目: defunSM/code
int main(int argc, char *argv[])
{
  struct Person *salman = Person_create("Salman Hossain", 18, 64, 118);
  struct Person *fahim = Person_create("Fahim Shariar", 18, 64, 118);

  printf("Salman is at memory location %p \n", salman);
  Person_print(salman);

  printf("Fahim is at memory location %p \n", fahim);
  Person_print(fahim);

  salman->age += 20;
  salman->height -= 2;
  salman->weight += 20;
  Person_print(salman);

  fahim->age += 20;
  fahim->weight += 40;
  Person_print(fahim);
  
  Person_destroy(salman);
  Person_destroy(fahim);
  
  return 0;

}
示例#4
0
文件: ex16.c 项目: alegros/lcthw
int main (int argc, char *argv[])
{
	// make two people structure
	struct Person *joe = Person_create(
			"Joe Alex", 32, 64, 140);
	struct Person *frank = Person_create(
			"Frank Blank", 20, 72, 180);

	// print them out and where they are in memory
	printf("Joe is at memory location : %p\n", joe);
	Person_print(joe);
	printf("Frank is at memory location : %p\n", frank);
	Person_print(frank);

	joe->age += 20;
	joe->height -= 2;
	joe->weight += 40;
	Person_print(NULL);

	frank->age += 20;
	frank->weight += 20;
	Person_print(frank);

	// clean up
	Person_destroy(joe);
	Person_destroy(frank);
	return 0;
}
示例#5
0
int main(int argc, char *argv[])
{
    struct Person joe = Person_create("Joe Alex", 32, 64, 140);

    struct Person frank = Person_create("Frank Blank", 20, 72, 180);

    //printf("Joe is at memory location: %p\n", joe);
    Person_print(joe);

    //printf("Frank is at memory location: %p\n", frank);
    Person_print(frank);

    //make everyone age 20 years and print them again
    joe.age += 20;
    joe.height -= 2;
    joe.weight += 40;
    Person_print(joe);

    frank.age += 20;
    frank.weight += 20;
    Person_print(frank);

    //destroy them both so we clean up
    Person_destroy(joe);
    Person_destroy(frank);

    return 0;
}
示例#6
0
文件: ex16.c 项目: haitongz/saber
int main(int argc, char *argv[])
{
	struct Person *joe = Person_create(
			"Joe Alex", 32, 64, 140);
	struct Person *frank = Person_create(
			"Frank Blank", 20, 72, 180);

	printf("Joe is at memory location: %p.\n", joe);
	Person_print(joe);

	printf("Frank is at memory location: %p.\n", frank);
	Person_print(frank);

	joe->age += 20;
	joe->height -=2;
	joe->weight += 40;
	Person_print(joe);

	frank->age += 20;
	frank->weight += 20;
	Person_print(frank);

	Person_destroy(joe);
	Person_destroy(frank);

	return 0;
}
示例#7
0
int main(int argc, char *argv[]) {
    // Make two people structures
    struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
    struct Person *frank = Person_create("Frank Blank", 20, 72, 180);

    // Print them out and where they are in memory
    printf("Joe is at memory location %p:\n", joe);
    Person_print(joe);

    printf("Frank is at memory location %p:\n", frank);
    Person_print(frank);

    // make everyone age 20 years and print them out again
    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    frank->age += 20;
    frank->weight += 20;
    Person_print(frank);

    // destroy them both so we can clean up
    //Person_destroy(NULL); // this should abort compilation but for some reason doesnt
    Person_destroy(joe); // --leak-check=full to see where memory leak is happening
    Person_destroy(frank);

    return 0;
}
int main(int argc, char *argv[])
{
  // make two people structures
  struct Person reppard = Person_create("Reppard Walker", 34, 64, 160);
  struct Person ash = Person_create("Ashley Walker", 30, 62, 115);

  Person_print(reppard);
  printf("Memory Address %p\n", &reppard);

  Person_print(ash);
  printf("Memory Address %p\n", &ash);

  // make everyone age 20 years and print them again
  reppard.age += 20;
  reppard.height -= 2;
  reppard.weight += 40;
  Person_print(reppard);

  ash.age += 20;
  ash.height -= 2;
  ash.weight += 20;
  Person_print(ash);

  // destroy them both so we clean up
  Person_destroy(reppard);
  Person_destroy(ash);

  return 0;
}
示例#9
0
int main(int argc, char *argv[])
{
    // make two people structures
    struct Person *sami = Person_create(
            "Sami Nieminen", 25, 170, 72);

    struct Person *joe = Person_create( 
            "Joe Alex", 32, 160, 60);

    printf("Joe is at memory location %p:\n", joe);
    Person_print(joe);

    printf("Sami is at memory location %p:\n", joe);
    Person_print(sami);

    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    Person_destroy(sami);
    Person_destroy(joe);

    return 0;

}
示例#10
0
int main(int argc, char const *argv[])
{
	//make two people structures
	struct Person *joe = Person_create(
		"Joe Alex", 32, 64, 140);
	struct Person *frank = Person_create(
		"Frank Blank", 20, 72, 180);

	//print them out and where they are in memory
	printf("Joe is at memory location %p:\n", joe);
	Person_print(joe);

	printf("Frank is at memory location %p:\n", frank);
	Person_print(frank);

	//make everyone age 20 years and print them again
	joe->age += 20;
	joe->height -= 2;
	joe->weight += 40;
	Person_print(joe);

	frank->age += 20;
	frank->weight += 20;
	Person_print(frank);

	//destroy them both so we clean up
	Person_destroy(joe);
	Person_destroy(frank);

	return 0;
}
示例#11
0
文件: ex16-2.c 项目: jtrim/lcthw
int main(int argc, char *argv[]) {

  // make two people structures
  struct Person joe = Person_create(
      "Joe Alex", 32, 64, 140);
  printf("--- '%s', from within main: %p\n", joe.name, &joe);

  struct Person frank = Person_create(
      "Frank Blank", 20, 72, 180);
  printf("--- '%s', from within main: %p\n", frank.name, &frank);

  // print them out and where they are in memory
  printf("Joe is at memory location %p:\n", (void *)&joe);
  Person_print(joe);

  printf("Frank is at memory location %p:\n", (void *)&frank);
  Person_print(frank);

  // make everyone age 20 years and print them again
  joe.age += 20;
  joe.height -= 2;
  joe.weight += 40;
  Person_print(joe);

  frank.age += 20;
  frank.weight += 20;
  Person_print(frank);

  // destroy them both so we clean up
  Person_destroy(joe);
  Person_destroy(frank);

  return 0;
}
示例#12
0
int main(int argc, char *argv[])
{
    // make two people structures
    struct Person *joe = Person_create(
    "Joe Alex", 32, 64, 140);

    struct Person *frank = Person_create(
    "Frank Blank", 20, 72, 180);

    // make one bird structure
    // bill is a struct, not a pointer to a struct
    struct Bird bill = bird_create(
    "Bill Robin", 1, 11, 1);

    // print them out and where they are in memory
    printf("Joe is at memory location: %p\n", joe);
    Person_print(joe);

    printf("Frank is at memory location: %p\n", frank);
    Person_print(frank);

    printf("Bill is at memory location: %p\n", &bill);
    bird_print(bill);

    // make everyone age 20 years and print them again
    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    frank->age += 20;
    frank->weight += 20;
    Person_print(frank);

    strncpy(bill.name, "billy", MAX_NAME);
    // Ensure last character is null.
    bill.name[sizeof(bill.name) - 1] = '\0';
    bill.age += 20;
    bill.wingspan += 1;
    bird_print(bill);

    // destroy every Person to clean up heap memory.
    // if comment out calls to Person_destroy, program runs.
    // Xcode Analyze reports
    // "Potential leak of memory pointed to by 'joe', same for frank
    // Xcode Instruments Profile leaks shows live bytes from malloc.
    Person_destroy(joe);
    Person_destroy(frank);

    return 0;
}
示例#13
0
int main(int argc, char *argv[]) {
  struct Person *kirill = Person_create("Kirill", 25, 74, 176);
  Person_print(kirill);
  Person_destroy(kirill);

  return 0;
}
示例#14
0
int main(int argc, char *argv[]) {
  struct Person *john = Person_create("John", 56, 190, 100);
  struct Person *frank = Person_create("Frank", 25, 100, 89);


  printf("Frank is stored at %p \n", frank);
  printf("John is store at %p \n", john);

  Person_print(john);
  printf("Adding age by 20 \n");
  john->age += 20;
  Person_print(john);

  Person_destroy(john);
  Person_destroy(frank);
}
示例#15
0
int main(int argc, char *argv[])
{
        struct Person *roman = Person_create(
                        "Roman Levin", 30, 175, 90);
        struct Person *alex = Person_create(
                        "Aleksandra Grochowska", 27, 175, 72);

        printf("Roman is at memory location %p:\n", roman);
        Person_print(roman);

        printf("Alex is at memory location %p:\n", alex);
        Person_print(alex);

        Person_destroy(roman);
        Person_destroy(alex);

        return 0;
}
示例#16
0
int main(int argc, char *argv[])
{
  // make two people structures
  struct Person *joe = Person_create(
      "Joe Alex", 32, 64, 140);

  struct Person *frank = Person_create(
      "Franck Blank", 20, 72, 180);

  // print them out and where they are in memory
  printf("Joe is at memory location: %p\n", joe);
  Person_print(joe);

  printf("Franck is at memory location %p\n", frank);
  Person_print(frank);

  // make everyone age 20 years and print them again
  joe->age += 20;
  joe->height -=2;
  joe->weight +=40;
  Person_print(joe);

  frank->age +=20;
  frank->weight += 20;
  Person_print(frank);

  // destroy them both so we clean up
  Person_destroy(joe);
  Person_destroy(frank);

  // Example of creating and assigning on the stack (difference of . / ->)
  // more info here http://stackoverflow.com/questions/10916799/how-to-create-a-struct-on-the-stack-in-c

  struct Person paul;

  paul.name="Paul Stack";
  paul.age = 42;
  paul.height = 130;
  paul.weight = 100;
  printf("name: %s\n \tAge: %d\n \tHeight: %d\n \tWeight: %d\n",
      paul.name, paul.age, paul.height, paul.weight);

  return 0;
}
示例#17
0
文件: exe.c 项目: stroxler/lcthw
int main(int argc, char* argv[]) {
    struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
    struct Person *frank = Person_create("Frank Blank", 20, 72, 180);

    // the %p is for pointer printing, it prints memory location in hex
    printf("Joe is at memory location %p:\n", joe);
    printf("Frank is at memory location %p:\n", frank);
    Person_print(joe);
    Person_print(frank);

    // age them
    joe->age += 20; joe->weight += 40;
    frank->age +=20; frank->height -= 2;
    Person_print(joe);
    Person_print(frank);

    // clean up
    Person_destroy(joe);
    Person_destroy(frank);
    return 0;
}
示例#18
0
文件: ex16.c 项目: nogwater/lcthw
int main(int argc, char *argv[])
{
	// make two people structures
	struct Person *joe = Person_create(
		"Joe Alex", 32, 64, 140);
	
	struct Person *frank = Person_create(
		"Frank Black", 20, 72, 180);
	
	// print them out and where they are in memory
	printf("Joe is at memory location %p:\n", joe);
	Person_print(joe);

	printf("Frank is at memory location %p:\n", frank);
	Person_print(frank);

	printf("A person takes up %ld bytes of RAM\n", sizeof(struct Person));

	// make everyone age 20 years and print them again
	joe->age += 20;
	joe->height -= 2;
	joe->weight += 40;
	Person_print(joe);

	// assert(joe->weight < 150);

	frank->age += 20;
	frank->weight += 20;
	Person_print(frank);

	// Person_print(NULL); // to break it

	// destroy them both so we clean up
	Person_destroy(joe);
	Person_destroy(frank);
	// Person_destroy(NULL); // to break it

	return 0;
}
示例#19
0
int main(int argc, char *argv[])
{

	// make two people structures
	struct Person *joe = Person_create(
		"Joe Alex", 32, 64, 140);

	struct Person *shai = Person_create(
		"Shai Wilson", 22, 54, 190);

	// print them out and where they are in memory
	printf("Joe is at memory location %p\n", joe );
	Person_print(joe);

	printf("Shai is at memory location %p\n", shai );
	Person_print(shai);

	// destroy them both 
	Person_destroy(joe);
	Person_destroy(shai);

}
示例#20
0
int main(int argc, char *argv[]) {
    struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
    struct Person *frank = Person_create("Frank Blank", 20, 72, 180);
    struct Person rhett;

    rhett.name = "Rhett Rogers";
    rhett.age = 27;
    rhett.height = 72;
    rhett.weight = 200;

    Person_print_stack(rhett);

    printf("Joe is at memory location %p:\n", joe);
    Person_print(joe);
    printf("Frank is at memory location %p:\n", frank);
    Person_print(frank);

    // make everyone age 20 years and print them again
    joe->age += 20;
    joe->height -= 2;
    joe->weight += 40;
    Person_print(joe);

    frank->age += 20;
    frank->weight += 20;
    Person_print(frank);

    rhett.age += 20;
    rhett.height += 1;
    rhett.weight -= 20;
    Person_print_stack(rhett);

    // destroy them both so we clean up
    Person_destroy(joe);
    Person_destroy(frank);

    return 0;
}
示例#21
0
文件: ex16.c 项目: akshar-raaj/LCTHW
int main(int argc, char *argv[])
{
    struct Person *akshar = Person_create("Akshar Raaj", 22, 165, 55);

    printf("akshar is at memory location %p\n", akshar);

    Person_print(akshar);

    struct Person real_akshar = *akshar;
    printf("Name is %s\n", real_akshar.name);

    Person_destroy(akshar);
    return 0;
}
示例#22
0
int main(int argc, char *argv[])
{
  struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
  struct Person *frank = Person_create("Frank Blank", 20, 72, 180);

  printf("Joe is at memory location %p:\n", joe);
  Person_print(joe);

  printf("Frank is at memory location %p:\n", frank);
  Person_print(frank);

  joe->age += 20;
  joe->height -= 2;
  joe->weight += 40;
  Person_print(joe);

  frank->age += 20;
  frank->weight += 20;
  Person_print(frank);

  Person_destroy(joe);
  Person_destroy(frank);


  //Extra Credit
  printf("\n----EXTRA CREDIT----\n");
  struct Person j2;
  j2.name = "j2";
  j2.height = 197;
  j2.age = 20;
  j2.weight = 97;

  Person_print_extra_credit(j2);
  Person_print(&j2);

  return 0;
}
示例#23
0
文件: ex16.c 项目: brianbyrne/learn_c
int main(int argc, char *argv[])
{
	struct Person onStack;
	onStack.name =  "Brian On Stack";
	onStack.age = 32;
	onStack.height = 174;
	onStack.weight = 14;
	
	printf("Brian is at memory location: %p\n", &onStack);
	Person_print2(onStack);
	
	struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
	
	struct Person *frank = Person_create("Frank Blank", 19, 60, 168);
	
	printf("Joe is at memory location: %p\n", joe);
	Person_print(joe);
	
	printf("Frank is at memory location: %p\n", frank);
	Person_print(frank);
	
	
	joe->age += 20;
	joe->height += 2;
	joe->weight += 40;
	Person_print(joe);
	
	frank->age += 20;
	frank->height += 2;
	frank->weight += 40;
	
	Person_destroy(joe);
	Person_destroy(frank);
	Person_print(NULL);
	 
}
示例#24
0
文件: ex16.c 项目: jessewmc/chard
int main(int argc, char* argv[]){
  struct Person* joe = Person_create("joejo", 32, 64, 140);
  struct Person* frank = Person_create("frankie", 20, 72, 180);

  printf("joe is at yo %p\n", joe);
  Person_print(joe);

  printf("frank is at yo %p\n", frank);
  Person_print(frank);

  joe->age += 20;
  joe->height -= 2;
  joe->weight += 40;
  Person_print(joe);

  frank->age += 20;
  frank->weight += 20;
  Person_print(frank);

  Person_destroy(joe);
  Person_destroy(frank);

  return 0;
}
示例#25
0
int main(int argc, char *argv[])
{
    // make 2 people structures
    struct Person *joe = Person_create("Joe Alex", 32, 64, 140);
    /* struct Person *frank = Person_create("Frank Blank", 20, 72, 180); */
    struct Person frank = {
        "Frank",
        22,
        60,
        140
    };

    Person_print_2(frank);

    // print them out and their memory location
    printf("Joe is at memory location: %p:\n", joe);
    Person_print(joe);

    /* printf("Frank is at memory location: %p:\n", frank); */
    /* Person_print(frank); */

    (*joe).age += 20;
    (*joe).height -= 2;
    (*joe).weight += 40;
    Person_print(joe);

    /* (*frank).age += 20; */
    /* (*frank).weight += 20; */
    /* Person_print(frank); */

    // destroy them both to clean up
    Person_destroy(joe);
    /* Person_destroy(frank); */

    return 0;
}