Thread: collecting stat info from a module

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    32

    collecting stat info from a module

    I have a pgm calling a function in a module.

    The program is to pass a file name to the module function - and then the module function will collect the stat information and return the stat info to the calling program.

    I have written the following in my calling pgm:

    Code:
    struct stat file_info;
    
    &file_info = statfile(filename);
    and then in my module function:

    Code:
    file_info statfile(name_type filename) {
          stat(filename, &file_info);
          return(file_info); }
    I am getting a compile error saying:
    incompatible types in return

    Can anyone suggest a solution?
    Sue

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    200
    Code:
    file_info statfile(name_type filename) {
          stat(filename, &file_info);
          return(file_info); }
    It looks as if you are declaring a function that returns type file_info. Therefore, "&file_info" doesnt really make any sense in the stat() call. It is analogous to calling some function funct(&int), which may be the case in your situation but I doubt it. Also, returning file_info is not very meaninful either. Or I am an idiot and/or am intepreting your code incorrectly...
    I go to encounter for the millionth time the reality of experience and to forge in the smithy of my soul the uncreated conscience of my race.

    Windows XP consists of 32 bit extensions and a graphical shell for a 16 bit patch to an 8 bit operating system originally coded for a 4 bit microprocessor, written by a 2 bit company, that can't stand 1 bit of competition.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    No - I think I am the idiot here!!

    The calling pgm has the requirement to collect stat information for selected files and write the information to another file.

    So - I thought I would call the initial pgm and pass the file name in as a command parameter.

    Then pass the parameter to the function in the module - which should collect the stat info - and pass it back to the calling pgm - which then copies it to the fields in the output file.

    Am I making hard work of this?

    Is there another way?

    Should I just call the function in the module and move all my other code (ie the field copies, and file writes) into the module?

    Your thoughts would be appreciated...
    Thanks
    Sue

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I dont think you really need to put the stat() call in a seperate function of its own. Here's some sample code for you to review and amend to suit:
    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    
    int main(int argc, char *argv[])
    {
    	struct stat mystat;
    	
    	if (argc != 2)
    	{
    		printf("Invalid args\n");
    		return(1);
    	}
    	
    	if (stat(argv[1], &mystat) == -1)
    	{
    		perror(argv[1]);
    		return (1);
    	}
    	
    	printf("stat worked, is ");
    	
    	if (S_ISREG(mystat.st_mode))		// can be done better
    		printf("a regular file\n");
    	else
    		printf("not a regular file\n");
    	return (0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Number Range Problem.
    By xamlit in forum C Programming
    Replies: 11
    Last Post: 01-26-2006, 12:55 PM
  2. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 03:12 PM
  3. Capturing file stat information
    By Sue Paterniti in forum C Programming
    Replies: 3
    Last Post: 04-15-2002, 05:47 AM
  4. Function basics
    By sjleonard in forum C++ Programming
    Replies: 15
    Last Post: 11-21-2001, 12:02 PM