Results 1 to 9 of 9

Thread: strcat error

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    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

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    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


  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    I could use fread, but still I never know how big the 2nd argument should be.
    Matt

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  6. #6

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    what is the MYSTRUCT used for?
    Matt

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  8. #8

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width