Okay, first, I should let you all know that I'm a relatively new programmer and I just can't seem to get functions right, so I apologise in advance if these are really stupid/obvious questions.
Anyway, to the actual programming now. This is a school project, kind of like hangman. I've been at it for weeks and I'm close to finally getting finished but these pesky error are getting in my way and I just can't fix them!
If anyone could help me eliminate these last few errors it would be greatly appreciated! And again, beginner programmer here, I probably made some cringe-worthy mistakes. Sorry for the lengthy code as well..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
typedef struct {
char title[50];
char hidden[50];
}Title;
void Film(Title* pT)
{
int i=0;
int number;
char movies[44][50];
FILE *fp = NULL;
fp = fopen("Film.txt", "r");
for(i=0; i<44; ++i)
{
fgets(movies[i], sizeof(movies[i]), fp);
}
fclose(fp);
number = (rand() % 44);
strcpy(pT->title, movies[number]);
}
char Star(Title* pT, char lowerc, char higherc, char character)
{
int val;
char c;
int lenMovie;
lenMovie = strlen(pT->title);
strcpy(pT->hidden, pT->title);
for(val=0; val <= lenMovie; val++)
{
c = pT->hidden[val];
if(c == lowerc || c == higherc)
{
pT->hidden[val] = character;
}
else if(c >= 'a' && c<= 'z')
{
pT->hidden[val] = '*';
}
else if(c >= 'A' && c<= 'Z')
{
pT->hidden[val] = '*';
}
else
{
pT->hidden[val] = c;
}
}
printf("%s", pT->hidden);
}
char Film_Guess(Title* pT, int attempt)
{
int guess[50], answer, size;
printf("What movie do you think it is: ");
scanf("%s", &guess);
size = strlen(pT->title);
answer = strncmp(pT->title, guess[50], size);
if(answer = 0)
{
printf("You beat the Film Genie, nce work!");
return 0;
}
else
{
attempt++;
return main();
}
}
int main(void)
{
char option;
int attempt = 0;
char lowerc, higherc, character, reply;
Title t;
srand(time(NULL));
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t Welcome Player\n\n\n");
while(attempt <= 5)
{
printf("\nWould you like to try: ");
scanf("%c", &reply);
if(reply == 'y' || reply == 'Y')
{
Film (&t);
Star(&t, lowerc, higherc, character);
printf("\n Would you like to guess a character(c) or the whole film(f):");
scanf("%c",&option);
if(option =='c' || option =='C')
{
printf("\nPlease enter a character: ");
scanf("%c", &character);
lowerc = tolower(character);
higherc = toupper(character);
Star(&t, lowerc, higherc, character);
}
else if(option =='f' || option =='F')
{
Film_Guess(&t, attempt);
}
else
{
printf("\nInvalid response");
return main();
}
}
else{
break;
}
}
if(reply == 'n' || reply == 'N')
{
printf("\nLoser");
return 0;
}
else
{
printf("\nInvalid response");
return main();
}
}