Thread: Nested Structures

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Not
    struct WIN32_FIND_DATA attr_struct;
    just
    WIN32_FIND_DATA attr_struct;
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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, 10:53 AM
  3. Nested Structures
    By Thantos in forum C Programming
    Replies: 2
    Last Post: 12-07-2003, 03:34 PM
  4. Nested structures
    By Supar in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2003, 09:27 PM
  5. Nested structures
    By Garfield in forum C Programming
    Replies: 8
    Last Post: 10-08-2001, 12:11 PM