I have a small problem why is this code not writting information into the userdata.txt file?
I am not getting any errors in code blocks it runs but the file does not get any data.
While in visual c++ the code gives me "debug assertion failed...expression: str(!=NUll)".
What am i doing wrong ?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE *spdata; //stream created(globaly)
int day, year; char month[16]; //Variables created(globaly)
int open_file(FILE *spdata); //creates a file function
void user_input( int, char[], int); //user input fucntion
int write_file(int , char[], int); //writes user input to file
int main()
{
open_file(spdata);
user_input(day,month,year);
write_file(day,month,year);
fclose(spdata); // file closed
getch();
}
int open_file(FILE *spdata)
{
spdata = fopen("userdate.txt","w"); //name of file created
if(spdata != NULL) // if file test is passed
printf("\nFile created");
else
printf("\nFile was not created"); //if file test failed
return 0;
}
void user_input( int day, char month[16], int year)
{
printf("\n\nEnter day: ");
scanf("%d",&day);
printf("Enter month: ");
scanf("%s", month);
printf("Enter year: ");
scanf("%d",&year);
}
int write_file(int day , char month[16], int year)
{
fprintf(spdata,"%d %s %d", day, month,year); //data written to file
printf("File has been written");
return 0;
}