You were close but you had a few problems. One you shouldn't put a semicolon after the while loop. The second is that you should read in data from the file so that it advances the internal pointer of the file.
Here is a copy of your program with modifications to give you the number of lines assuming that each line of the file is less than 100 characters long.
CODE
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
FILE *open;
// Temporarily hold a string of the file (100 chars)
char temp[100];
// Set total = 0, not 1. Makes no sense.
int total=0;
open = fopen("input.txt","r");
while(!feof(open))
{
// Missing part, read in data and count
// NOTE: Don't put a semicolon after the while loop
fgets(temp,100,open);
total++;
}
// Print the total
printf("%d",total);
fclose(open);
getch();
return 0;
}
I have put some in code comments to show you what I am doing and where I am putting the changes. This should help you out.
Enjoy!
"At DIC we be file reading code ninjas with attitude!"
This post has been edited by Martyr2: 6 Jan, 2008 - 04:54 PM