Created
February 8, 2015 18:50
-
-
Save eroltutumlu/9a454b30d976dac306b4 to your computer and use it in GitHub Desktop.
Pointer ile struct'a bağlanma
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| /* Structure declaration */ | |
| struct personCatalog { | |
| char name[50]; | |
| char address[50]; | |
| char cityState[50]; | |
| char zipCode[7]; | |
| } ; | |
| const int maxNumberOfPeople = 3;; | |
| //function to fill structures | |
| void getPerson (struct personCatalog *ArrayOfPointers[]); | |
| int main(int argc, const char * argv[]) { | |
| struct personCatalog *pointerArray[maxNumberOfPeople]; | |
| getPerson(pointerArray); | |
| } | |
| void getPerson (struct personCatalog *ArrayOfPointers[]){ | |
| struct personCatalog *tempPointer; | |
| char stringCollector[512]; | |
| int num = 0; | |
| while ((num < maxNumberOfPeople) && (gets(stringCollector) != 0) ) { | |
| tempPointer = (struct personCatalog *) malloc(sizeof(struct personCatalog)); | |
| strcpy(tempPointer->name, stringCollector); | |
| gets(tempPointer->address); | |
| gets(tempPointer->cityState); | |
| gets(tempPointer->zipCode); | |
| ArrayOfPointers[num] = tempPointer; | |
| printf("name %s\n", ArrayOfPointers[num]->name); | |
| printf("address %s\n", ArrayOfPointers[num]->address); | |
| printf("cityState %s\n", ArrayOfPointers[num]->cityState); | |
| printf("zipCode %s\n", ArrayOfPointers[num]->zipCode); | |
| num++; | |
| } | |
| //ArrayOfPointers[num] = '\0'; this crashed at end of array | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment