🔒 Locked
Loading .txt Files
Advertisement
Original Post
I am having trouble loading a .txt file into my Win 32 program. I think it has something to do with the memory. I get the path name to the file using the GetOpenFileName function and use this code to load it:
FILE* File;
long Size;
char* text;
File = fopen(FileName, "r");
fseek(File, 0, SEEK_END);
Size = ftell(File);
rewind(File);
text = (char*)malloc(Size);
fread(text, 1, Size, File);
SetWindowText(hEdit, text);
fclose(File);
free(text);
It comes up in the Edit Control but it reads testýýýý1
any idea how to solve this?
Thanx
|
[Resist Windows XP''s Invasive Production Activation Technology!]
dude, get away from C, get on the C++ bandwagon.
I thought for awhile that I should learn C before C++, but then I got really pissed at the terrible pointers deal with C and switched.
Code to read in from a file in C++ is almost identical to code to read in from the keyboard:
#include <iostream.h>
#include <fstream.h>
int main(void)
{
ifstream fin("data.txt");
int x;
cout<<"read in from keyboard"<<endl;
cin>>x;
cout<<"read in from file"<<endl;
fin>>x;
fin.close();
return 0;
}
see how easy!!! No dealing with pointers!!! No learning new functions!!! It's so easy!!! This is why I switched right here!!!
Edited by - capn_midnight on January 7, 2002 12:56:06 PM
I thought for awhile that I should learn C before C++, but then I got really pissed at the terrible pointers deal with C and switched.
Code to read in from a file in C++ is almost identical to code to read in from the keyboard:
#include <iostream.h>
#include <fstream.h>
int main(void)
{
ifstream fin("data.txt");
int x;
cout<<"read in from keyboard"<<endl;
cin>>x;
cout<<"read in from file"<<endl;
fin>>x;
fin.close();
return 0;
}
see how easy!!! No dealing with pointers!!! No learning new functions!!! It's so easy!!! This is why I switched right here!!!
Edited by - capn_midnight on January 7, 2002 12:56:06 PM
quote:
Original post by Anonymous Poster
Same thing in c (notice, no pointers either):
|
Sorry to be a nit picker, but what do you call FILE *in? It sure looks like a pointer to me.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement
