Пример #1
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;
}
Пример #2
0
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;
}
Пример #3
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);

	return 0;
}
Пример #4
0
/*
   The MAIN function.
*/
int main(int argc, char *argv[]) {
  // make two people structures
  Person joe = Person_create(
	  "Joe Alex", 32, 64, 140);
  Person frank = Person_create(
	  "Frank Blank", 20, 72, 180);
  
  // print them out
  Person_print(joe);
  Person_print(frank);
  
  // make everyone age 20 years and print them again
  printf("\n20 years later...\n\n");
  joe.age += 20;
  joe.height -= 2;
  joe.weight += 40;
  Person_print(joe);
  
  frank.age += 20;
  frank.weight += 20;
  Person_print(frank);

  // clean up
  free(joe.name);
  free(frank.name);
  
  return 0;
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
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);
	
	//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;
}
Пример #8
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 nd 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 so we clean up
  free(joe.name);
  free(frank.name);

  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;
}
Пример #10
0
int
main(int argc, char **argv)
{
  struct Person joe;
  joe.name = "Joe Alex";
  joe.age = 32;
  joe.height = 64;
  joe.weight = 140;

  struct Person frank;
  frank.name = "Frank Blank";
  frank.age = 20;
  frank.height = 72;
  frank.weight = 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);

  return 0;
}
Пример #11
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;

}
Пример #12
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;
}
Пример #13
0
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;

}
Пример #14
0
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;
}
Пример #15
0
int main(int argc, char *argv[]) {
  // create a couple Person structs
  struct Person joe = Person_create("Joe Alex", 32, 64, 140);
  struct Person *frank = Person_pointer_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_pointer_print(frank);

  
  // time warp
  joe.age += 20;
  joe.height -= 2;
  joe.weight += 40;
  Person_print(joe);

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

  
  // free up the memory allocated to the structs
  Person_pointer_destroy(frank);
  
  return 0;
}
Пример #16
0
int main(int argc, char *argv[])
{
  struct Person joe = Person_create("Joe Alex", 32, 64, 140);
  Person_print(joe);

  printf("----\n");

  // just for fun
  Person_print(Person_create("Frank Blank", 20, 72, 180));

  return 0;
}
Пример #17
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;
}
Пример #18
0
int main(int argc, char *argv[]) {
  struct Person *kirill = Person_create("Kirill", 25, 74, 176);
  Person_print(kirill);
  Person_destroy(kirill);

  return 0;
}
Пример #19
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);
}
Пример #20
0
int main(int argc, char *argv[]) {
    struct Person *saisimon = Person_create("Saisimon", 23, 180, 190);
    struct Person *younix = Person_create("Younix", 23, 172, 120);
    printf("saisimon in memory is %p.\n", saisimon);
    Person_print(saisimon);
    printf("younix in memory is %p.\n", younix);
    Person_print(younix);

    saisimon -> age += 5;
    saisimon -> height += 5;
    saisimon -> weight -= 20;
    Person_print(saisimon);

    Person_detory(saisimon);
    Person_detory(younix);
    return 0;
}
Пример #21
0
int main(int argc, char *argv[])
{
    struct Person dmitry = Person_create(
        "Dmitry Lobaskov", 27, 180, 70);

    Person_print(dmitry);

    return 0;
}
Пример #22
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;
}
Пример #23
0
int main(int argc, char * argv[])
{
  Person p1;
  Person p2;
  p1.year = 1989;
  p1.month = 8;
  p1.date = 21;
  p1.name = strdup("Amy");
  p2.year = 1991;
  p2.month = 2;
  p2.date = 17;
  p2.name = strdup("Bob");
  Person_print(& p1);
  Person_print(& p2);
  free (p1.name);
  free (p2.name);
  return EXIT_SUCCESS;
}
Пример #24
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;
}
Пример #25
0
Файл: ex16e.c Проект: jsks/lcthw
int main(void) {
    // Let's initialise our struct
    Person joe;
    joe.name = strdup("Joe Alex");
    joe.age = 32;
    joe.height = 64;
    joe.weight = 140;

    Person_print(joe);

    return 0;
}
Пример #26
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);

    // 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;
}
Пример #27
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 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;
}
Пример #28
0
int main(int argc, char *argv[]) {
  // make two structures
  struct Person joe = Person_create("Joe Alex", 32, 64, 140);
  struct Person frank = Person_create("Joe Alex", 32, 64, 140);

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

  printf("Frank is at mem 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);

  return 0;
}
Пример #29
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);

}
Пример #30
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;
}