1 / 8

Recitation 8

Recitation 8. Quiz Time. No computers. Outline. Project 2 Help Programmer’s view of memory Pointer arrays (will probably be on exam) Dynamic memory allocation. Project 2. char airports[MAX_AIRPORTS][4] char airport_cities [MAX_AIRPORTS][MAX_STRING_LEN]

marisa
Télécharger la présentation

Recitation 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recitation 8

  2. Quiz Time No computers

  3. Outline • Project 2 Help • Programmer’s view of memory • Pointer arrays (will probably be on exam) • Dynamic memory allocation

  4. Project 2 • char airports[MAX_AIRPORTS][4] • char airport_cities[MAX_AIRPORTS][MAX_STRING_LEN] • scanf(“%[^\n]%c”, string, &newLine); • scanf(“%[A-Za-z]”, string); • sscanf(string, “%d %d %c”, &int1, &int2, &char1); • sscanf(string, “%d : %d : %c”, &int1, &int2, &char1); • Strings end in ‘\0’ character • Automatically scanning in newline character

  5. Programmer’s view of memory • 1D arrays • 2D arrays • scanf • printf • strcpy • Write a program that uses strstr to find a string “fire” within the string “campfire” and print out

  6. Pointer Arrays • ptr_array.c

  7. Dynamic Memory Allocation • Variables are deallocated once you leave the function (unless they are global) • No longer need global variables because of pointers • Malloc! • Returns a pointer • Write a program that mallocs an integer, sets the value to 5, and prints the integer

  8. Time left? • Malloc an array of 5 integers, set them to {0, 1, 2, 3, 4}, then print them out using a for-loop

More Related