/* F95callC1.C */ /* Copyright 2002 Lahey Computer Systems, Inc. */ #include #include #include #define common(name) name##_ /* appending _ matches name generated by LF95 */ extern struct { float total_c; int total_f; } common(mycommon); int GenTable(int *start, int *end) { char endstring[10]; int f; float c; FILE *output; int lines_in_table, lines_left; /* Fortran leaves us on the line just printed, so we need to output */ /* an extra newline before we do any I/O */ printf("\n"); printf("IN C\n"); printf("%s%s","Where should the table end (Enter an ", "integer less than 30) ? "); gets(endstring); *end=atoi(endstring); output=fopen("F95callC.out","w"); printf("Placing Fahrenheit to Centigrade table in F95CALLC.OUT\n"); lines_left = lines_in_table = *end - *start + 1; for (f=*start; lines_left > 0; f++, lines_left--) { c=5./9.*(f-32); common(mycommon).total_c+=c; common(mycommon).total_f+=f; fprintf(output,"%d F = %f C\n",f,c); } fclose(output); printf("Table generated\n"); // MessageBox(NULL,"table","generated",MB_OK); /* After the last thing output from C, it is easiest to stay on the */ /* same line so the next thing output from Fortran can use standard */ /* carriage control */ printf("LEAVING C"); /* note the lack of a \n */ /* We flush stdout to make sure that all output is out of the buffers */ /* and displayed on the screen. If we don't do this, Fortran may */ /* end up displaying its output before C */ fflush(stdout); return(lines_in_table); }