80 likes | 177 Views
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]
E N D
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] • 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
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
Pointer Arrays • ptr_array.c
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
Time left? • Malloc an array of 5 integers, set them to {0, 1, 2, 3, 4}, then print them out using a for-loop