Nested Structures

This is a discussion on Nested Structures within the C Programming forums, part of the General Programming Boards category; I am trying to back up windows file attributes using a nested structure to save the path and file name ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    15

    Nested Structures

    I am trying to back up windows file attributes using a nested structure to save the path and file name along with the windows attributes structure. I have simplifed the code to the snippet below. Compile (gcc) gives
    error: field `attr_struct' has incomplete type.

    Assistnace will be very much appreciated.
    Leon

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    FILE *out;
    
    int get_attrs(char *dir)
    {
      int result;
      char char_buffer[500];
      char char_dir[500];
      char shortpath[500];
      WIN32_FIND_DATA FindFileData;
      HANDLE hFind;
    
      struct file_attrs {
        char filename[500];
        struct WIN32_FIND_DATA attr_struct;
      } file_data;
    
      strcpy(char_buffer,dir);
      strcat(char_buffer,"\\*.*");
    
      hFind = FindFirstFile(char_buffer, &FindFileData);
    
      do
      {  
        if (!strcmp(FindFileData.cFileName, ".")) 
          continue;
        if (!strcmp(FindFileData.cFileName, "..")) 
          continue;
    
        strcpy(file_data.filename, char_buffer);
        file_data.attr_struct = FindFileData;
        fwrite(&file_data, sizeof(file_data),1, out);
    
      } while (FindNextFile(hFind, &FindFileData));
      FindClose(hFind);
    }
    
    int main(void)
    {
      out = fopen("attrs.dat", "w");
      if ( out == NULL)
      {
        printf("could not open attrs.dat");
        exit(1);
      }
      get_attrs("d:\\c_projects");
      fclose(out);
      exit(0);
    }

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Not
    struct WIN32_FIND_DATA attr_struct;
    just
    WIN32_FIND_DATA attr_struct;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    strcmp(), strcpy(), and strcat() are in <string.h>; exit() is in <stdlib.h>. Include those header files.

    The variable result doesn't appear to be used.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested Structures Possible?
    By thetinman in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2007, 11:22 AM
  2. Nested Structures - User Input
    By shazg2000 in forum C Programming
    Replies: 2
    Last Post: 01-09-2005, 09:53 AM
  3. Nested Structures
    By Thantos in forum C Programming
    Replies: 2
    Last Post: 12-07-2003, 02:34 PM
  4. Nested structures
    By Supar in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2003, 08:27 PM
  5. Nested structures
    By Garfield in forum C Programming
    Replies: 8
    Last Post: 10-08-2001, 12:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21