Hey, so i'm trying to count to number of lines in a text file, and this is what i have so far.
cpp
while(!feof(fp)) {
fscanf(fp, "%s\n", junk);
numOfElements++;
}
but the value of numOfElements, no matter how many lines i put in the file always is 21. I have no idea why this is happening. This isn't all of my program, but this is the part that isn't working. The main objective of what i'm doing is upon compile time I don't know how many different "Listings" i'm going to have. a Listing is a class that i've built. I'm using the new operator to create the number of "Listings" that i'm going to need. Each line in the file is going to be a new listing. So when I run my program I have 21 LIstings, but with the test data that i'm using I only need 5. This is the first time that i'm using new, but it's doing exactly what I want it to, the line is
cpp
x = new Listing[numOfElements];
but i can't get the number of lines in the file though. I would think that numOfElements increased each time is goes to the next line until the end of the file will give me the number of lines in the file, but it's not.
Could someone please point me in the right direction.
Thanks
S0n1C!