Files
seer/tests/hellodprintf/hellodprintf.cpp
T

56 lines
1.1 KiB
C++
Raw Normal View History

2024-05-04 10:46:39 -05:00
#include <string>
#include <iostream>
#include <iomanip>
2024-05-20 15:50:54 -05:00
#include <stdio.h>
#include <stdarg.h>
FILE* logfile = NULL;
2024-05-04 10:46:39 -05:00
extern "C" {
int log_msg (const char* format, ...) {
2024-05-20 15:50:54 -05:00
int n;
va_list args;
// init the variable length argument list
va_start(args, format);
n = vfprintf(logfile, format, args);
// cleanup the variable length argument list
va_end(args);
return n;
}
}
extern "C" {
void fortranfunction_ (int* count);
2024-05-04 10:46:39 -05:00
}
int main (int argc, char** argv) {
2024-05-20 15:50:54 -05:00
const char* filename = "logfile.txt";
logfile = fopen(filename, "w");
if (logfile == NULL) {
fprintf(stderr, "Failed to open logfile: %s\n", filename);
return 1;
}
2024-05-04 10:46:39 -05:00
int count = 10;
int nfact = 1;
int n;
std::cout << " C++ loop" << std::endl;
for (n=1; n<=count; n++) {
nfact = nfact * n;
// printing the value of n and its factorial
std::cout << std::setw(12) << n << std::setw(14) << nfact << std::endl;
}
fortranfunction_(&count);
2024-05-20 15:50:54 -05:00
fclose(logfile);
2024-05-04 10:46:39 -05:00
return 0;
}