The Canadian Guitar Forum banner

1 - 5 of 5 Posts

·
Registered
Joined
·
1,348 Posts
Discussion Starter #1
so for my summative, that's due in 4 days, and I am yet to start. I chose to do a database, with movies, it includes the movie title, release year, genre, and rating. It's saved in a txt file. I need to read it in the the program and do some stuff with it. I'm thinking aboust having an add data entry, delete data entry, sort by title, sort by year, sort by genre, and sort by rating. Then it will output the new data into a new txt file. I really need to do well on this summative because I think i'm failing the course, so If anybody knows C, that would be willing to help me with stupid problems that will arise in the code, that would be greatly appreciated.

thanks guys
 

·
Registered
Joined
·
324 Posts
I have programmed in C before... not since high school, but I've done Java recently... which has some similar coding. Anyway, let me know if you need help... i still have my high school notes (sad, i know...)
 

·
Registered
Joined
·
1,348 Posts
Discussion Starter #3
jane said:
I have programmed in C before... not since high school, but I've done Java recently... which has some similar coding. Anyway, let me know if you need help... i still have my high school notes (sad, i know...)
well, for starters...this code doesnt do anything, and i dont know why, It's supposed to read in records and store them into an array of structures, then print them. But it doesnt do anything at all.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAX_TITLE_CHARS 50
#define MAX_MOVIES 50
#define MAX_GENRE_CHARS 20
#define MAX_RATING_CHARS 5
#define MAX_MOVIES 50
#define MAX_RECORD_CHARS 120

#define DELIMITER ','
#define NEWLINE_CHAR '\n'

#define ORIGINAL_DATABASE "/moviedatabase.txt"

typedef struct movieType
{
char title[MAX_TITLE_CHARS+1];
int year;
char genre[MAX_GENRE_CHARS+1];
char rating[MAX_RATING_CHARS+1];
} movieType, *pMovieType;


void parseMovieRecord (movieType *movie, char *record)
{
char temp [MAX_TITLE_CHARS + 1];
int i, j;

i = 0;
j = 0;

while (record != DELIMITER)
temp [j++] = record [i++];

temp [j] = 0;
i++;
strcpy ( movie->title, temp);

j = 0;
while (record != DELIMITER)
temp [j++] = record [i++];

temp [j] = 0;
i++;
movie->year = atoi (temp);

j = 0;
while (record != DELIMITER)
temp [j++] = record [i++];

temp [j] = 0;
i++;
strcpy ( movie->genre, temp);

j = 0;
while (record != NEWLINE_CHAR)
temp [j++] = record [i++];

temp [j] = 0;
strcpy (movie->rating, temp);

}

int getMovieData (movieType *movie, int *numMovies)
{
FILE *inFile;
int errorCode, i;
char record [MAX_RECORD_CHARS + 1];

if (!(inFile = fopen (ORIGINAL_DATABASE, "r")))
errorCode = -1;
else
{
i = 0;
fgets (record, MAX_RECORD_CHARS + 1,inFile);
while (!feof (inFile))
{
fgets (record, MAX_RECORD_CHARS + 1,inFile);
if (!feof (inFile))
{
if (i == MAX_MOVIES - 1)
{
errorCode = -2;
}
else
{
parseMovieRecord(&movie, record);
i++;
}
}
}

fclose (inFile);
*numMovies = i;
errorCode = 0;
return errorCode;
}
}


void outputMovieData (movieType *movie, int numMovies)
{
int i;

for (i = 0; i < numMovies; i++)
{
printf ("%s,", movie.title);
printf ("%i,", movie.year);
printf ("%s,", movie.genre);
printf ("%s,", movie.rating);
}
}

int main()
{
movieType movies [MAX_MOVIES];
int numMovies = 0;

getMovieData(movies, &numMovies);
outputMovieData(movies, numMovies);

system("PAUSE");
}
 

·
Registered
Joined
·
1,348 Posts
Discussion Starter #4
nevermind...i fixed it... moviedatabase.txt was actually called moviedatabase.txt.txt


stupid XP:mad:
 
1 - 5 of 5 Posts
Top