Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    267

    [C++] Errore in compilazione

    Sto provando a compilare per la prima volta un programmain c++ con g++ da windows ma come provo ho questo output;

    codice:
    $ g++ bfc.c -o bfc
    In file included from bfc.c:12:
    huffman.h:500:3: warning: no newline at end of file
    In file included from bfc.c:13:
    lz.h:349:3: warning: no newline at end of file
    bfc.c: In function `int main(int, char**)':
    bfc.c:221: error: invalid conversion from `void*' to `unsigned char*'
    bfc.c:275:2: warning: no newline at end of file
    Qualcuno sa spiegarmi un pò il significato? è la prima volta che me li trovo davanti...

  2. #2
    Mah... Qualche punto e virgola?
    Prova a postare le prime righe di bfc...
    Folle e' l'uomo che parla alla luna.
    Stolto chi non le presta ascolto.

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    267
    Grazie per l'intervento dekdek.... ecco qui:

    codice:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "huffman.h"
    #include "lz.h"
    
    
    int ReadWord32( FILE *f )
    {
    unsigned char buf[4];
    fread( buf, 4, 1, f ); //reads 4 one byte sized pieces from file f
    return (((unsigned int)buf[0])<<24) +
    (((unsigned int)buf[1])<<16) +
    (((unsigned int)buf[2])<<8) +
    (unsigned int)buf[3];
    } //returns a 32bit integer composed of the 4 bytes taken in.

  4. #4
    Mah, prova a fare come ti dice, inserisci una riga vuota alla fine di huffman.h e di lz.h e vedi che succede...
    Folle e' l'uomo che parla alla luna.
    Stolto chi non le presta ascolto.

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    267
    Si effettivamente l'errore di new line sembra andato via.. Mah.. strana sta cosa..
    Comunque... è rimasto questo:

    codice:
    bfc.c: In function `int main(int, char**)':
    bfc.c:221: error: invalid conversion from `void*' to `unsigned char*'
    bfc.c:275:2: warning: no newline at end of file
    Cioè non capisco... in c++ non posso passare argomenti alla funzione main?

  6. #6
    No, o meglio, glieli passa il sistema operativo quando richiami il programma. Il loro tipo e' fissato, non puoi deciderlo arbitrariamente. Pero' char dovrebbe essere giusto...
    Folle e' l'uomo che parla alla luna.
    Stolto chi non le presta ascolto.

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    267
    Originariamente inviato da dekdek
    No, o meglio, glieli passa il sistema operativo quando richiami il programma. Il loro tipo e' fissato, non puoi deciderlo arbitrariamente. Pero' char dovrebbe essere giusto...
    si mi pare di aver capito cossa intendi... Comunque ti posto la funzione in questione chissà ci vedi qualche cavolata....

    codice:
    int main( int argc, char **argv )
    {
    FILE *f;
    unsigned char *in, *out, command, algo=0;
    unsigned int insize, outsize=0;
    char *inname, *outname;
    
    /* Check arguments */
    if( argc < 4 )//not enough arguments for the program to run properly
    {
    Help( argv[ 0 ] ); //just in case the program is named something else
    return 0; //exit
    }
    
    /* Get command */
    command = argv[1][0]; /*the first argument after the program name lets the
    program know whether it is compressing or decompressing*/
    if( (command != 'c') && (command != 'd') )
    {
    Help( argv[ 0 ] ); //if you didn't pick either c or d
    return 0;
    }
    
    /* Get algo */
    if( argc == 5 && command == 'c' ) /*if there are enough parms and you wanted
    compression*/
    {
    algo = 0; //initializes algo
    if( strcmp( argv[2], "h" ) == 0 ) algo = 2; //2 is for huffman
    if( strcmp( argv[2], "l" ) == 0 ) algo = 9; //9 is for lz77
    if( !algo ) //if algo has not changed
    {
    Help( argv[ 0 ] ); //displays help
    return 0;
    }
    inname = argv[ 3 ]; //sets inname to the 3rd value in program call
    outname = argv[ 4 ]; //sets outname to the 4th valu in program call
    }
    else if( argc == 4 && command == 'd' ) /*if there are the right number of
    arguments and command =d*/
    {
    inname = argv[ 2 ]; //argument after d becomes inname
    outname = argv[ 3 ]; //argument after that becomes outname
    }
    else //user doesn't know what's going on
    {
    Help( argv[ 0 ] );
    return 0;
    }
    
    /* Open input file */
    f = fopen( inname, "rb" ); /*open a file in read and binary mode and identify
    it by f*/
    if( !f ) //if file does not exist
    {
    printf( "Unable to open input file \"%s\".\n", inname );
    return 0;
    }
    
    /* Get input file size */
    insize = GetFileSize( f ); /*calls the GetFileSize function on f and puts
    the value in insize*/
    //Austin's Code /*Check File size. If greater than 2^32, abort*/
    if (insize >(4000000))
    {
    printf ("File size is too large. Aborting... \n");
    return 0;
    }
    /* Decompress? */
    if( command == 'd' ) //if user wants to decompress
    {
    /* Read header */
    algo = ReadWord32( f ); // dummy
    algo = ReadWord32( f ); /*first word in a file compressed using this
    algorithm determines the algo to decompress it*/
    outsize = ReadWord32( f ); /*next word is the size of the original file*/
    insize -= 12; //the first three words (12bytes) of the infile are gone
    }
    
    /* Print operation... */
    switch( algo )
    {
    case 2: printf( "Huffman " ); break;
    case 9: printf( "LZ77 " ); break;
    }
    switch( command )
    {
    case 'c': printf( "compress " ); break;
    case 'd': printf( "decompress " ); break;
    }
    printf( "%s to %s...\n", inname, outname );
    
    /* Read input file */
    printf( "Input file: %d bytes\n", insize ); /*outputs name of file and the
    number of bytes in it*/
    in = (unsigned char *) malloc( insize ); /*puts a pointer to the newly
    allocated chunk of memory the size of inzize in in*/
    if( !in ) //if the memory was not allocated
    {
    printf( "Not enough memory\n" );
    fclose( f );
    return 0;
    }
    fread( in, insize, 1, f ); /*takes the file f and reads the entire thing
    into the memory addressed by in one byte at a time*/
    fclose( f ); //closes file f
    
    /* Show output file size for decompression */
    if( command == 'd' )
    {
    printf( "Output file: %d bytes\n", outsize );
    //shows the outfile name and its size (calculated according to insize)
    }
    
    
    /* Open output file */
    f = fopen( outname, "wb" ); /*opens the file called outname and calls it f
    the file is writable and binary*/
    if( !f ) //file did not open
    {
    printf( "Unable to open output file \"%s\".\n", outname );
    free( in ); //frees the in memory and exits program
    return 0;
    }
    
    /* Compress? */
    if( command == 'c' )
    {
    /* Write header */
    fwrite( "BCL1", 4, 1, f ); //writes the dummy header
    WriteWord32( algo, f ); //writes the name of algo used
    WriteWord32( insize, f ); //writes the size of the original file
    
    /* Worst case buffer size */
    outsize = (insize*104+50)/100 + 384; /*I don't know where these numbers
    came from*/
    }
    
    /* Allocate memory for output buffer */
    out = malloc( outsize ); /* makes outsize room in memory and puts the pointer
    to it in out*/
    if( !out )//memory was not allocated
    {
    printf( "Not enough memory\n" );
    fclose( f ); //close file
    free( in ); //free the memory addressed by in
    return 0; //exit program
    }
    
    /* Compress or decompress */
    if( command == 'c' ) //if user wanted to compress
    {
    switch( algo ) //algo is the index of the algorithms
    {
    case 2:
    outsize = Huffman_Compress( in, out, insize ); /*compresses
    in buffer, writes it to out buffer, and returns the size of the
    out buffer*/
    break;
    case 9:
    outsize = LZ_Compress( in, out, insize ); /*compresses
    in buffer, writes it to out buffer, and returns the size of the
    out buffer*/
    break;
    }
    printf( "Output file: %d bytes (%.1f%%)\n", outsize,
    100*(float)outsize/(float)insize );
    }
    else
    {
    switch( algo )
    {
    case 2:
    Huffman_Uncompress( in, out, insize, outsize );/*uncompresses
    in buffer and writes it to out buffer)*/
    break;
    case 9:
    LZ_Uncompress( in, out, insize );/*uncompresses
    in buffer and writes it to out buffer)*/
    break;
    }
    }
    
    /* Write output file */
    fwrite( out, outsize, 1, f );/*writes outsize pieces of the out buffer
    to f one byte at a time*/
    fclose( f ); //closes f
    
    /* Free memory */
    free( in ); //deallocates buffer addressed by in
    free( out ); //deallocates buffer addressed by out
    
    return 0;
    }

  8. #8

    Re: [C++] Errore in compilazione

    Originariamente inviato da dybart
    Sto provando a compilare per la prima volta un programmain c++ con g++ da windows ma come provo ho questo output;

    codice:
    $ g++ bfc.c -o bfc
    In file included from bfc.c:12:
    huffman.h:500:3: warning: no newline at end of file
    In file included from bfc.c:13:
    lz.h:349:3: warning: no newline at end of file
    bfc.c: In function `int main(int, char**)':
    bfc.c:221: error: invalid conversion from `void*' to `unsigned char*'
    bfc.c:275:2: warning: no newline at end of file
    Qualcuno sa spiegarmi un pò il significato? è la prima volta che me li trovo davanti...
    dimmi se la riga 221 è questa

    codice:
    out = malloc( outsize ); /* makes outsize room in memory and puts the
    il fatto che il file sia con estensione .c ti suggerisce che il file è un sorgente C e non C++

    se lo compili così

    $ gcc bfc.c -o bfc

    vedrai che non avrai alcun errore, questo perché C++ impone delle restrizioni al codice legacy C, che ha ereditato da questo linguaggio, una di queste è proprio quell'errore

    In C questo cast non è necessario

    codice:
    out = (unsigned char*) malloc( outsize ); /* makes outsize room in memory and
    in C++ , questo cast è obblicatorio

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2003
    Messaggi
    267
    Si il problema era proprio quello alla riga suggerita da te (la 221)
    Mancava il cast... Grazie molto....

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.