C++ (Cpp) fopen Examples

C++ (Cpp) fopen - 30 examples found. These are the top rated real world C++ (Cpp) examples of fopen extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
static int cmpfile(const char *str, const char *path, const char *fname)
{
    char filename[1024], *buffer;
    int ret;
    FILE *file;

    sprintf(filename, "%s%c%s", path, dir_sep, fname);
    file = fopen(filename, "rb");
    if (!file) {
        if (conf.strip)
            strcat(filename, ".strip");
        else
            strcat(filename, ".normal");
        file = fopen(filename, "rb");
    }
    if (!file) {
        printf("Error: test result file could not be opened.\n");
        exit(1);
    }

    buffer = loadfile(file);
    if (strcmp(buffer, str) != 0)
        ret = 1;
    else
        ret = 0;
    free(buffer);
    fclose(file);

    return ret;
}
Example #2
0
int main(int argc, char** args) {
    FILE* instruction_file = fopen(args[1], "r");
    char** instructions = NULL;
    int lines = get_instructions(instruction_file, &instructions);
    fclose(instruction_file);

    var** input_variables = NULL;
    int num_input_variables = get_input_variables(instructions, lines, &input_variables);

    var** temp_variables = NULL;
    int num_temp_variables = get_temporary_variables(instructions, lines, &temp_variables);

    var** output_variables = NULL;
    int num_output_variables = get_output_variables(instructions, lines, &output_variables);

    FILE* value_file = fopen(args[2], "r");
    char* string = (char *) malloc(256 * sizeof(char *));
    while (fscanf(value_file, "%[^\n]\n", string) == 1) {
        int i;
        for (i = 0; i < num_input_variables; i++) {
            input_variables[i] -> value = string[i*2] - '0';
        }
        run_program(instructions, lines,
                    input_variables, num_input_variables,
                    temp_variables, num_temp_variables,
                    output_variables, num_output_variables
                   );
    }
    return 0;
}
Example #3
0
int filecopy( char *oldfilename, char *newfilename)
{
    FILE *oldfile;
    FILE *newfile;
    char c_temp;

    if( (oldfile = fopen( oldfilename, "r") ) == NULL ) {
        return -1;
    }
    if( (newfile = fopen( newfilename, "w") ) == NULL ) {
        return -1;
    }

    while(1) {
        c_temp = fgetc( oldfile);
        if( c_temp == EOF)
            break;
        fputc( c_temp, newfile);
    };

    fclose( oldfile);
    fclose( newfile);

    return 0;
}
Example #4
0
static void
initFiles(void)
{
    char buf[BUFSIZ];

    snprintf(buf,BUFSIZ,"%s%s_%d.json", dirpath, prefix, queryid);
    tachojson= fopen(buf,"w");
    if( tachojson == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d_mal.csv",dirpath, prefix, queryid);
    tachomal= fopen(buf,"w");
    if( tachomal == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d_stmt.csv", dirpath, prefix, queryid);
    tachostmt= fopen(buf,"w");
    if( tachostmt == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
    snprintf(buf,BUFSIZ,"%s%s_%d.trace", dirpath, prefix, queryid);
    tachotrace= fopen(buf,"w");
    if( tachotrace == NULL) {
        fprintf(stderr,"Could not create %s\n",buf);
        exit(-1);
    }
}
Example #5
0
int main( int argc, char *argv[ ] ) {
    FILE *in, *out;

    in = fopen( "input.dat", "r" );
    if ( in == NULL ) {
        perror( "input.dat" );
        return 1;
    }
    out = fopen( "output.dat", "w" );
    if ( out == NULL ) {
        perror( "output.dat" );
        return 1;
    }
    int x, p, n, y, rc;
    while ( fscanf( in, "%x %d %d %x", &x, &p, &n, &y ) != EOF ) {
        rc = setbits( x, p, n, y );
        fprintf( out, "setbits(0x%x, %d, %d, 0x%x) = 0x%x\n", x, p, n, y, rc );
        printf( "0x1234 | 0x0000 = %x\n", x | 0 );
        printf( "0x1234 | 0x1111 = %x\n", x | ~0 );
    }

    fclose( in );
    fclose( out );

    return 0;
}
Example #6
0
File: io.c Project: qingl97/ENSEIRB
/*************************************************************************
* This function writes out the partition vectors for a mesh
**************************************************************************/
void WriteMeshPartition(char *fname, int nparts, int ne, idxtype *epart, int nn, idxtype *npart)
{
    FILE *fpout;
    int i;
    char filename[256];

    sprintf(filename,"%s.epart.%d",fname, nparts);

    if ((fpout = fopen(filename, "w")) == NULL)
        errexit("Problems in opening the partition file: %s", filename);

    for (i=0; i<ne; i++)
        fprintf(fpout,"%d\n", epart[i]);

    fclose(fpout);

    sprintf(filename,"%s.npart.%d",fname, nparts);

    if ((fpout = fopen(filename, "w")) == NULL)
        errexit("Problems in opening the partition file: %s", filename);

    for (i=0; i<nn; i++)
        fprintf(fpout,"%d\n", npart[i]);

    fclose(fpout);


}