Question

I'm doing a project in C for school and and I'm testing out one of the functions to read in a random title from a file and storing that film and that film same film but with asterisks replacing the letters in a struct.

Anyway, I keep getting the same error of "Expected declaration before 'struct'" when trying to run the code and I've tried loads of different things but I keep getting the same error, I don't even know if my code will work! If you see any error in my code feel free to point them out :)!

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

typedef struct {
            char title[500];
            char hiddentitle[500];
        }Title;

char Film(Title t){

FILE *fopen(), *fp;

    fp = fopen("Film.txt", "r");

    int i=0;
    int j;
    int number;
    int lenMovie;
    char c, film;
    char movies[45][500];
    int val =0;
    
    
    while( i<45 ){

        fgets(movies[i], sizeof(movies[i]), fp);
        i++;

    }

    srand(time(NULL));
    number = (1+(rand() % 45));
    
    t.title[500] = movies[number];


    printf("%s", t.title);
    lenMovie = strlen(t.title);

    while(val <= lenMovie)
    {
        c = t.title[val];

        if(c >= 'a' && c<= 'z'){

            
            t.hiddentitle[val] == '*';
        }

        else if(c >= 'A' && c<= 'Z'){

            t.hiddentitle[val] == '*';
        }
        else{

            t.hiddentitle[val] == c;
        }

        val++;
    }
    printf("\n%s", t.hiddentitle);
    fclose(fp);
}

int main(void){

    Film (struct Title);
    
    }
Was it helpful?

Solution

You have

typedef struct {
            char title[500];
            char hiddentitle[500];
        }Title;

So in main() use:

int main(void){
Title t;

    Film (t);

    }

OTHER TIPS

In your main() function you are doing this, which is invalid:

Film (struct Title);    

Instead, you must pass an argument in your call to File():

Title t = { }; // initialize it
Film(t);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top