Sorry about the post earlier and not putting in the Code Tags:
My Error is at : ptr = initmovie( title, director, duration, year );
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
struct movie {
char * title; //movie title
char * director; //director's name
int year; //release year
int duration; //expressed in minutes
struct movie *next; //pointer to next movie
};
typedef struct movie MovieRecord;
typedef struct movie *MovieRecordPtr;
void NewMovie(void);
struct movie *initmovie( char *, char *, int, int );
void insertmovie( struct movie * );
void printlist( struct movie * );
void printmovie( struct movie * );
//struct movie *strPtr = (struct movie *) NULL;
//struct movie *endPtr = (struct movie *) NULL;
MovieRecordPtr strPtr = NULL;
MovieRecordPtr endPtr = NULL;
int main(int argc, char *argv[])
{
char title;
char director;
int year;
int duration;
struct movie *ptr;
NewMovie();
printlist(strPtr);
system("PAUSE");
return 0;
}
void NewMovie(void)
{
char title;
char director;
int year;
int duration;
struct movie *ptr;
int count = 0;
int amount = 0;
printf("\nHow many movies do you want to store? ");
scanf("%d", &amount);
while(amount != 0)
{
count++;
printf("\nMovie #%d ", count);
printf("\t Title: \t\t");
scanf("%s", &title);
char c =getchar();
//DisplayEntireList( &startPtr, m_name );
printf("\n");
printf("\t\t Director: \t\t");
scanf("%s", &director);
char d =getchar();
//DisplayEntireList( &secondPtr, d_name );
printf("\n");
printf("\t\t Duration of minutes: \t");
scanf("%d", &duration);
//DisplayEntireList( &thirdPtr, m_duration );
printf("\n");
printf("\t\t Year: \t\t\t");
scanf("%d", &year);
ptr = initmovie( title, director, duration, year );
insertmovie( ptr );
//DisplayEntireList( &fourthPtr, m_year );
}
}
struct movie *initmovie( char *title, char *director, int duration, int year )
{
struct movie *ptr;
ptr = (struct movie *) calloc( 1, sizeof(struct movie ) );
if( ptr == NULL )
return (struct movie *) NULL;
else {
strcpy( ptr->title, title );
ptr->director = director;
return ptr;
}
}
void insertmovie( struct movie *new )
{
struct movie *temp, *prev; /* similar to deletenode */
if( strPtr == NULL ) { /* if an empty list, */
strPtr = new; /* set 'head' to it */
endPtr = new;
strPtr->next = NULL;
return;
}
temp = strPtr;
while( strcmp( temp->title, new->title) < 0 ) {
temp = temp->next;
if( temp == NULL )
break;
}
if( temp == strPtr ) {
new->next = strPtr;
strPtr = new;
}
else {
prev = strPtr;
while( prev->next != temp ) {
prev = prev->next;
}
prev->next = new;
new->next = temp;
if( endPtr == prev )
endPtr = new;
}
}
void printlist( struct movie *ptr )
{
while( ptr != NULL )
{
printmovie( ptr );
ptr = ptr->next;
}
}
void printmovie( struct movie *ptr )
{
printf("\nMovie #");
printf("\t\t%s\n", ptr->title );
printf("\n");
printf("\t\t%s, ", ptr->director );
printf("\t\t%d, ", ptr->duration );
printf("\t\t%d, ", ptr->year );
printf("\n");
}