|
-
Jun 12th, 2001, 02:45 PM
#1
Thread Starter
Hyperactive Member
strcat error
Code:
int filelen;
filelen = fseek(fp,0,SEEK_END);
char buffer[sizeof(filelen)];
rewind(fp);
char ch;
ch = getc(fp);
while(ch!=EOF){
strcat(buffer,ch);
ch = getc(fp);
}
error C2664: 'strcat' : cannot convert parameter 1 from 'char (*)[4]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
anyway i don't understand what the problem here is, any ideas?
Matt 
-
Jun 12th, 2001, 02:50 PM
#2
Frenzied Member
You are trying to put a char array of 4 in to a single char. Make char ch; char ch*;
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 12th, 2001, 02:54 PM
#3
Monday Morning Lunatic
sizeof(filelen) returns 4 because it's the size of the variable, not the size of the file.
Use:
Code:
char *buffer = new char[filelen];
You'd have to delete[] it afterwards though:
Code:
int filelen;
filelen = fseek(fp,0,SEEK_END);
char *buffer = new char[filelen];
buffer[0] = 0;
rewind(fp);
char ch;
ch = getc(fp);
while(ch != EOF){
strcat(buffer,ch);
ch = getc(fp);
}
Also, can't you just use fread?
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
-
Jun 12th, 2001, 03:07 PM
#4
Thread Starter
Hyperactive Member
I could use fread, but still I never know how big the 2nd argument should be.
Matt 
-
Jun 12th, 2001, 05:39 PM
#5
Monday Morning Lunatic
size_t fread( void *buffer, size_t size, size_t count, FILE *stream );
Code:
MYSTRUCT toread;
fread(&toread, sizeof(toread), 1, fp);
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
-
Jun 13th, 2001, 02:59 PM
#6
Thread Starter
Hyperactive Member
what is the MYSTRUCT used for?
Matt 
-
Jun 13th, 2001, 03:01 PM
#7
Monday Morning Lunatic
It's just a type placeholder. It signifies that you put the size of the item you are reading, and the 3rd argument is the number of items of that size.
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
-
Jun 13th, 2001, 03:06 PM
#8
Thread Starter
Hyperactive Member
But when you compile it expects a structure or at least needs one. Anyway here what I have
Code:
FILE *fp;
fp = fopen("C:/Matt/files.txt", "rb");
//int filelen;
//filelen = fseek(fp,0,SEEK_END);
MYSTRUCT toread;
fread(&toread,sizeof(toread),1,fp);
SendMessage(editbx,WM_SETTEXT,0,(LPARAM)toread);
by-the-way thanks alot for your help!
Matt 
-
Jun 13th, 2001, 03:07 PM
#9
Monday Morning Lunatic
No no no...change MYSTRUCT to whatever you're reading from the 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
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
|