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;
}

Recommended Answers

All 3 Replies

>> I keep getting this error

what error?

>> 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)

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.