0

In my void parseListings() I have an if statment that checks for a "N/A" condition and if its not there, i need to append the unit number. the problem is that when the condition is true it appends the city name twice. Does anyone have a quick fix to this problem? any help would be greatly apreciated. This program reads from a delimited file, and then writes it to another file. the delimited file looks like this:


123 Cherry Tree Drive#330#Condo#2#1#275900#Toronto#
14 Leaside Lane#N/A#House#4#2#445500#Brampton#
2478 Waterfront Avenue#N/A#House#5#3#899900#Mississauga#
7 Lucky Lane#1206#Condo#3#2#310000#Toronto#
51 West Street#32#Townhouse#4#2#450000#Brampton#
193 Crystal Road#1519#Condo#1#1#250750#Toronto#
3914 Tangerine Terrace#N/A#House#3#1#427750#Mississauga#
10 Redding Road#N/A#House#4#2#512350#Toronto#
76 Old School Avenue#227#Townhouse#3#2#475000#Toronto#
90 Brookhaven Terrace#N/A#House#4#2#512750#Brampton#

And the output is supposed to look like this:


  • 3
    Please don't dump your whole code. Provide the least amount of code that illustrates your problem. – Lee Taylor May 26 '14 at 02:00
  • @LeeTaylor I personally prefer too much than not enough (even though I agree that the perfect quantity is ideal; but it's not realistic to ask for it...). However, in that instance, a better indentation (and much less newlines in code) would probably help a lot. – 7heo.tk May 26 '14 at 02:02
  • See [`while (!feof(file))` is always wrong](http://stackoverflow.com/questions/5431941/while-feof-file-is-always-wrong) for details on why you're not reading correctly. I'm not sure that's your double-city problem, but that's a separate discussion. – Jonathan Leffler May 26 '14 at 02:08

1 Answers1

3

Your unitNum array is of size 10.

You use:

sprintf(append," Unit #%s , ",token);
strcpy(listing[n].unitNum, append);

You've not allowed any space for the unit number, so you're overflowing your array, so what follows is printed too, and what follows is (surprise) the city. So, increase the dimension on unitNum to at least 15 (that will allow for a 4 digit unit number).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278