Reputation: 35
I am writing a program that has to read from a delimited file and then print the output. The delimiter is a pound sign '#' . Right now I keep getting the error " field not found: buildingType". I know this is because of my nested structure but for my program i was told that its how its supposed to be written. My return type for my parseListing() method needs to be void which is why I think I might be coming up with errors also. I need to find away to fix this without changing my return type from void. Also in my delimited file, there are some values that are listed as "N/A" and I need those not to show up when I print the characters from the file. My delimited file looks like this except with no spaces in between each line(I put spaces into the text box for formatting purposes on this site).
Here is my code so far.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char buildingType[10];
int numBedrooms;
int numBathrooms;
}Propertylisting;
typedef struct {
Propertylisting propertylisting;
char address[100];
char unitNum [10];
char city [50];
void printPropertyListing(Listing l) {
printf("%s %s %s\n%s %d %d %d\n\n", l.address, l.unitNum, l.city, l.buildingType, l.numBedrooms, l.numBathrooms, l.listPrice);
}
Upvotes: 0
Views: 54
Reputation: 9642
Here, your PropertyListing
is a field in your Listing
structure. You're trying to assign to listing[n].buildingType
, which doesn't exist in your Listing
structure.
They do exist in your PropertyListing
structure however, of which one is included in your Listing
structure under the name propertyListing
. You can simply access propertyListing
as a standard structure field, then access the members of PropertyListing
through that member. As an example, see the following code:
listing[n].propertyListing.buildingType; // For the building type string
listing[n].propertyListing.numBedrooms; // For the number of bedrooms
And so on.
Upvotes: 1