Hey all....thanks for previous help...starting to do about 4 hrs C programming a day.
question with this line (function prototype and function itself)
Code:
void close_function(FILE *fp, char buffer);
I am not sure how to pass FILE *fp & buffer to the close_function function. I understand buffer isn't a value, but i cannot tell what it is. It's not a char array, and does not return a value.
Code:
// Write a function that opens a new temporary file with a specified mode. All temporary files created by this function should automatically be closed and deleted when the program terminates. (Hint: Use the atexit() library function).
#include <stdio.h>
#include <stdlib.h>
void close_function(FILE *fp, char buffer);
void start_function(void);
int main( void )
{
atexit(close_function);
start_function();
return 0;
}
void start_function(void)
{
FILE *fp;
char mode[4];
char buffer[80];
tmpnam(buffer);
while (1)
{
puts("\nEnter a mode (max 3 characters): ");
gets(mode);
if ( (fp = fopen(buffer, mode )) != NULL )
{
printf("\nSuccessful opening %s in mode %s.\n", buffer, mode);
}
break;
}
}
void close_function(FILE *fp, char buffer)
{
fclose(fp);
remove(buffer);
puts("Done, temp file closed and deleted.\n");
}
Thanks all for help who puts in time and effort to help me learn this language.