Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 31st, 2006, 8:12 PM   #1
Ghosty
Newbie
 
Join Date: May 2005
Location: NJ
Posts: 18
Rep Power: 0 Ghosty is on a distinguished road
Send a message via AIM to Ghosty
compile problem: unix program to monitor access times

This is my code. As you can see it doesn't do much.

#include <iostream>
#include <string>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

using namespace std;

int main(int argc, char * argv[]){
	//check for correct number of files
	if(argc < 2){
		cout << "You must specify a file name" << endl;
		return 1;
	}
	if(argc > 11){
		cout << "Error: Too many file names specified." << endl;
		return 1;
	}

	//define structure and other variables
	struct stat {
		mode_t    st_mode;
		ino_t     st_ino;
		dev_t     st_dev;
		nlink_t   st_link;
		uid_t     st_uid;
		gid_t     st_gid;
		off_t     st_size;
		time_t    st_atime;
		time_t    st_mtime;
		time_t    st_ctime;
		blksize_t st_blksize;
		blkcnt_t  st_blocks;
	}; 
	
return 0;	
}

I get the following error when I try to compile:

lab2.cpp: In function ‘int main(int, char**)’:
lab2.cpp:30: error: expected ‘;’ before ‘.’ token
lab2.cpp:31: error: expected ‘;’ before ‘.’ token
lab2.cpp:32: error: expected ‘;’ before ‘.’ token

The structure is taken straight from my book. My guess is that I'm missing an include file somewhere. If I comment out the time_t lines, the code compiles. The program seems free of syntax errors so I'm not sure what the problem is. Any help is appreciated.
Ghosty is offline   Reply With Quote
Old Oct 31st, 2006, 8:15 PM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
#include <time.h>?
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Oct 31st, 2006, 8:22 PM   #3
Ghosty
Newbie
 
Join Date: May 2005
Location: NJ
Posts: 18
Rep Power: 0 Ghosty is on a distinguished road
Send a message via AIM to Ghosty
I discovered that stat is already defined in stat.h. From my text I got the impression that I had to define it manually.

For time.h, I might need it eventually but I don't need it for the snippet I posted above.
Ghosty is offline   Reply With Quote
Old Oct 31st, 2006, 8:28 PM   #4
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 3 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
time_t is defined in time.h. (I think) Why would you define stat if it is already defined in <sys/stat.h>?
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
compile program with command line arguments squirrel C 27 Jun 27th, 2006 10:44 AM
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
problem...a simple program... n00b C++ 13 Sep 22nd, 2005 5:08 AM
Fahrenheit / Celsius compile problem andrewgray C++ 20 Jul 8th, 2005 11:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC