|
-
Apr 22nd, 2001, 02:18 AM
#1
Could someone show me how to load a file into an array?
-
Apr 22nd, 2001, 04:22 AM
#2
Frenzied Member
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);
-
Apr 22nd, 2001, 02:49 PM
#3
Im sorry, i didnt explain enough, i meant with the Win32 API.
-
Apr 22nd, 2001, 03:02 PM
#4
Monday Morning Lunatic
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
-
Apr 22nd, 2001, 04:50 PM
#5
-
Apr 22nd, 2001, 05:37 PM
#6
Monday Morning Lunatic
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
-
Apr 22nd, 2001, 05:40 PM
#7
I write my programs in C, and when they are all done, i put them into asm. So the function cant be language specific.
-
Apr 22nd, 2001, 05:45 PM
#8
Monday Morning Lunatic
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
-
Apr 23rd, 2001, 06:21 PM
#9
Hyperactive Member
You can use FindFile and FindNext file functions. I made a project doing that ill try and go find it.
Matt 
-
Apr 23rd, 2001, 06:30 PM
#10
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|