Results 1 to 10 of 10

Thread: Loading a file

  1. #1
    ChimpFace9000
    Guest

    Post

    Could someone show me how to load a file into an array?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    If you mean every char of a file in array then maybe something like this.
    Code:
    #include <stdio.h>
    
    FILE *f;
    int i = 0;
    f = fopen("c:\\textfile","r");
    char c;
    fseek(f,0,SEEK_END);
    int filelen = ftell(f);
    char *filechar= new char[filelen];
    while((c = getc(f)) != EOF)
    {	
          i++;
          ar[i] = ftell(f);
    }
    fclose(f);
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    ChimpFace9000
    Guest
    Im sorry, i didnt explain enough, i meant with the Win32 API.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Does it really make much difference how you do it?

    However, see www.winprog.org/tutorial for the code to load from a file.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    ChimpFace9000
    Guest
    Yes, it does.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Okay...just out of interest...why?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    ChimpFace9000
    Guest
    I write my programs in C, and when they are all done, i put them into asm. So the function cant be language specific.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Fair enough I just assumed that since you were using C the standard library would be enough
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    You can use FindFile and FindNext file functions. I made a project doing that ill try and go find it.
    Matt

  10. #10
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    this may be what you wanted..
    Code:
    int findfiles(char *p)
    {
    WIN32_FIND_DATA Find;
    HANDLE hfind;
    BOOL hfind2;
    unsigned int i=0;
    char *dirname[i];
    
    
    hfind = FindFirstFile(p, &Find);
    //MessageBox (NULL, Find.cFileName, "first file", 0);
    if(hfind == INVALID_HANDLE_VALUE){
             MessageBox(NULL, "Error opening file", "FindFiles", MB_OK|MB_ICONERROR);
    
    } else
    
    SendMessage(NULL, LB_ADDSTRING, 0, (LPARAM) Find.cFileName);
    
    do{
    hfind2 = FindNextFile(hfind, &Find);
             dirname[i] = new char[strlen(Find.cFileName)] ;
             dirname[i] = Find.cFileName;
    
    
    SendMessage(listbx,LB_ADDSTRING,0,(LPARAM) Find.cFileName);
    
    }while(hfind2!=0);
    
    
    FindClose(hfind);
    
             for(i=i;i>0;i--)
                    delete[] dirname[i];
    return 0;
    }
    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width