Thread: error in code

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    18

    error in code

    in this code, i''m trying to view data already present in a file on the screen.but i keep getting an error like "error: expected '=' , ',' , ';' , 'asm' or '__attribute__' before * token" at the file declarations
    Code:
    extern void ygs_turkce(void);
    extern void ygs_matematik(void);
    extern void ygs_tarih(void);
    extern void ygs_fizik(void);
    extern void ygs_kimya(void);
    extern void ygs_biology(void);
    extern void ygs_felsefe(void);
    extern void ygs_cografya(void);
    extern void ygs_geometry(void);
    
    FILE *fygsturkce;
    FILE *fygsmatematik;
    FILE *fygstarih;
    FILE *fygsfizik;
    FILE *fygskimya;
    FILE *fygsbiology;
    FILE *fygsfelsefe;
    FILE *fygsgeometry;
    FILE *fygscografya;
    
    extern void ygs_matematik(void)
    {
        char mat[1000];
        fygsmatematik=fopen("YGS_matematik.txt","r");
        while(fscanf(fygsmatematik,"%s",&mat[])!='END')
            fscanf(fygsmatematik,"%s",&mat[]);
        return 0;
    }
    
    extern void ygs_turkce(void)
    {
        char turkce[1000];
        fygsturkce=fopen("YGS_turkce.txt","r");
        while(fscanf(fygsturkce,"%s",&turkce[])!='END')
            fscanf(fygsturkce,"%s",&turkce[]);
        return 0;
    }
    
    extern void ygs_tarih(void)
    {
        char tarih[1000];
        fygstarih=fopen("YGS_tarih.txt","r");
        while(fscanf(fygstarih,"%s",&tarih[])!='END')
            fscanf(fygstarih,"%s",&tarih[]);
        return 0;
    }
    
    extern void ygs_fizik(void)
    {
        char fizik[1000];
        fygsfizik=fopen("YGS_fizik.txt","r");
        while(fscanf(fygsfizik,"%s",&fizik[])!='END')
            fscanf(fygsfizik,"%s",&fizik[]);
        return 0;
    }
    
    extern void ygs_kimya(void)
    {
        char kimya[1000];
        fygskimya=fopen("YGS_kimya.txt","r");
        while(fscanf(fygsturkce,"%s",&kimya[])!='END')
            fscanf(fygskimya,"%s",&kimya[]);
        return 0;
    }
    
    extern void ygs_biology()(void)
    {
        char bio[1000];
        fygsbiology=fopen("YGS_biology.txt","r");
        while(fscanf(fygsbiology,"%s",&bio[])!='END')
            fscanf(fygsbiology,"%s",&bio[]);
        return 0;
    }
    
    extern void ygs_felsefe(void)
    {
        char fels[1000];
        fygsfelsefe=fopen("YGS_felsefe.txt","r");
        while(fscanf(fygsfelsefe,"%s",&fels[])!='END')
            fscanf(fygsfelsefe,"%s",&felse[]);
        return 0;
    }
    
    extern void ygs_geometry()(void)
    {
        char geo[1000];
        fygsgeometry=fopen("YGS_geometry.txt","r");
        while(fscanf(fygsgeometry,"%s",&geo[])!='END')
            fscanf(fygsgeometry,"%s",&geo[]);
        return 0;
    }
    
    extern void ygs_cografya(void)
    {
        char cog[1000];
        fygscografya=fopen("YGS_cografya.txt","r");
        while(fscanf(fygscografya,"%s",cog[])!='END')
            fscanf(fygscografya,"%s",&cog[]);
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Did you #include <stdio.h>?

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    First of all lose all those extern keywords... every last one of them.

    If your main is below these functions... you also don't need the declarations at the top.

    Next move your FILE* declaritors into the functions, not at global scope.
    Test each file to see if it actually opened or not.
    Don't use fscanf() twice for each line... simply because you'll end up only seeing every other entry.
    fscanf() will never return END... it might return EOF, but only after reading the last line twice.
    If you want to see the stuff on the screen you've got to put it on the screen.
    And... you need to close your file when you're done with it.

    For Example:
    Code:
    void ygs_matematik(void)
    {
        FILE *fygsturkce;
        char mat[1000];
    
        fygsmatematik=fopen("YGS_matematik.txt","r");
        if (!  fygsmatematik )
         {
            printf("Could not open YGS_matematic.txt\n");
            return;
         }
    
        while(fscanf(fygsmatematik,"%s",mat) > 0)
           printf("%s \n", mat);
     
        fclose(fygsmatematik);
    }
    However... since these are all doing the exact same thing, just with different files you could just as easily make one function that does it all...

    Code:
    void DisplayFile(char *FileName)
    {
        FILE *fptr;
        char buf[1000];
    
        fptr=fopen(FileName,"r");
        if (!  fptr)
         {
            printf("Could not open %s \n",FileName);
            return;
         }
    
        while(fscanf(fptr, "%s", buf) > 0)
           printf("%s \n", buf);
     
        fclose(fptr);
    }
    And call the function with different file names...
    Code:
    // in your main function...
    
    DisplayFile("YGS_matematik.txt");
    DisplayFile("YGS_kimya.txt");
    // and so on
    Hint: Always look for the simplest way to do things!

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    18
    thank you.it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get something error with my code.
    By imbax8299 in forum C Programming
    Replies: 13
    Last Post: 05-26-2011, 09:00 AM
  2. Help with code, I can't seem to fix the error
    By saszew in forum C Programming
    Replies: 2
    Last Post: 11-13-2008, 08:28 PM
  3. Code error
    By DeepFyre in forum C++ Programming
    Replies: 9
    Last Post: 12-27-2004, 01:32 AM
  4. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  5. i have an error in this code help?
    By ssjnamek in forum C++ Programming
    Replies: 12
    Last Post: 01-26-2002, 10:48 PM