2. Открытие файлов

3KB
.clang-format
int main(int argc, char *argv[])
{
	FILE* inputFile = fopen(argv[1], "r");
	FILE* outputFile = fopen(argv[2], "w");

    // malloc
    // read from input file
    // calculate
    // write to output file
    
    fclose(inputFile);
    fclose(outputFile);
}
Вариант реорганизации и исправления кода
int main(int argc, char *argv[])
{
	FILE* inputFile = fopen(argv[1], "r");
    // file is opened?
    // malloc
    // read from input file
    fclose(inputFile);

    // calculate
    
	FILE* outputFile = fopen(argv[2], "w");
    // file is opened?    
    // write to output file
    fclose(outputFile);
}

Last updated