0

Im just trying to read a file to see if i did the code correctly but I keep getting this error. Any help is appreciated.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node
{
char name[15];
char title[15];
int year;
struct Node *next;
struct Node *prev;
};
typedef struct Node* Box;
Box build_node(FILE *inputp);
int main()
{
Box head=NULL,temp;
FILE *inputp, *outputp;
inputp = fopen("CD_input.txt", "r");
outputp=fopen("output.txt", "w");
head=build_node(inputp);
printf( "%s, %s, %d \n", head->name, head->title, head->year); /*just a test for the line#1. Delete if it works*/
return 0;
}
Box build_node(FILE *inputp)
{
Box temp=NULL;
temp=(Box)malloc(sizeof(struct Node));
fscanf(inputp, "%s", &temp->name);
fscanf(inputp, "%s",  &temp->title);
fscanf(inputp, " %d", &temp->year);
temp->next=NULL;
temp->prev=NULL;
return temp;
}
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

>> I keep getting this error

what error?

it compiles fine but everytime i try to run the program i get an error that says:

Debug Assertion Failed
Expression: (stream !=NULL)

0

You need to check that fopen() returned a non-NULL pointer. It will return NULL if the file can not be opened (such as the file does not exist when opening for read or you don't have permissions to open for write).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.