Guest User

Untitled

a guest
Jan 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. /*Create a struct  that holds the information for a house including at a
  2.  * minimum the street, number, city, and zip code.  Create 10 of these.
  3.  * Sort them any way you would like and print them sorted.*/
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. typedef struct {
  9.   char Street[52];
  10.   char City[32];
  11.   char Zip[6];
  12.   char Phone[20];
  13. } HouseInfo;
  14.  
  15. HouseInfo Instances[10];
  16.  
  17. char* GetLine (char* String, size_t Length) {
  18.    char* StringPtr = fgets (String, Length, stdin);
  19.  
  20.    if (StringPtr != NULL) {
  21.       size_t Last = strlen (String) - 1;
  22.  
  23.       if (String[Last] == '\n') {
  24.          String[Last] = '\0';
  25.       }
  26.   }
  27.   return StringPtr; //returns a pointer to the string
  28. }
  29.  
  30. char* LoadStreet (HouseInfo Instances[]) {
  31.    printf("Enter Street: \n");
  32.    char* StreetPtr = GetLine(Instances->Street, sizeof(Instances->Street));
  33.    
  34.    return (StreetPtr);
  35. }
  36.  
  37. char* LoadCity (HouseInfo Instances[]) {
  38.    printf("Enter Street: \n");
  39.    char* CityPtr = GetLine(Instances->City, sizeof(Instances->City));
  40.    
  41.    return (CityPtr);
  42. }
  43.  
  44. char* LoadZip (HouseInfo Instances[]) {
  45.    printf("Enter Street: \n");
  46.    char* ZipPtr = GetLine(Instances->Zip, sizeof(Instances->Zip));
  47.    
  48.    return (ZipPtr);
  49. }
  50.  
  51. char* LoadPhone (HouseInfo Instances[]) {
  52.    printf("Enter Street: \n");
  53.    char* PhonePtr = GetLine(Instances->Phone, sizeof(Instances->Phone));
  54.    
  55.    return (PhonePtr);
  56. }
  57.  
  58. void LoadStruct (HouseInfo Instances[]) {
  59.    
  60. }
  61.  
  62. void Sort (int Zip) {
  63.    
  64. }
  65.  
  66. int main (void) {
  67.    for (int i = 0; i < 10; i++) {
  68.       LoadStreet(Instances[i]);
  69.    }
  70.    
  71.    for ( int i = 0; i < 10; i++) {
  72.       puts(Instances[i].Street);
  73.       //puts(Instances[i].City);
  74.       //puts(Instances[i].Zip);
  75.       //puts(Instances[i].Phone);
  76.    }
  77.    
  78.    return 0;  
  79. }
  80.  
  81. // Compiler Output pasted below... //
  82.  
  83. ample.c: In function ‘main’:
  84. Sample.c:68:7: error: incompatible type for argument 1 of ‘LoadStreet’
  85. Sample.c:30:7: note: expected ‘struct HouseInfo *’ but argument is of type ‘HouseInfo’
Add Comment
Please, Sign In to add comment