Like Tree1Likes
  • 1 Post By hk_mp5kpdw

Syntax error befor printf.

This is a discussion on Syntax error befor printf. within the C Programming forums, part of the General Programming Boards category; I am making this code but it gives error. the compiler says : syntax error before printf at line no ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    2

    Syntax error befor printf.

    I am making this code but it gives error.
    the compiler says : syntax error before printf at line no 9.
    any help in this regard ?
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    FILE *fp1 ,*fp2;
    char ca , cb;
    int i,j;
    char A[i][j],B[i][j],x[i][j];
    char file1[1024],file2[1024];
    printf(" Enter file1: ",file1);
    gets(file1);
    printf("Enter file2: ",file2);
    gets(file2);
    fp1=fopen(file1,"r");
    if ( fp1 == NULL )
        {
            printf("Cannot open %s for reading \n", file1 );
            exit(1);
         while ((fgets(fp1)!=EOF)
        {
         for(i=0,i<2500,i++)
         {
           for(j=0,j<5,j++)
         }
    
    
         fscanf(fp1,"%s",&A[i][j])
        }
    
    
        fp2=fopen(file2,"r");
        if ( fp2 == NULL )
        {
            printf("Cannot open %s for reading \n", file2 );
            exit(1);
        }
    
    
        while ((fgets(fp1)!=EOF)
        {
         for(i=0,i<2500,i++)
         {
           for(j=0,j<5,j++)
         }
    
    
         fscanf(fp2,"%s",&B[i][j])
        }
    
    
        x[i][j]=strcmp(A[i][1],B[i][1]);
        if(x=0)
        {
        printf("%s /n %s " x[i][j])
        }
    
    
        fclose(fp1)
        fclose(fp2)
        return 0;
        }

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    You forgot an open "{" after main.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > int i,j;
    > char A[i][j],B[i][j],x[i][j];
    Even if your compiler supports variable length arrays, it won't appreciate initialising them with the undefined values in i and j
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    printf(" Enter file1: ",file1);
    gets(file1);
    printf("Enter file2: ",file2);
    gets(file2);
    Don't use gets, fgets should be used instead.

    The printf statements should not be using the file1/file2 variables. First, you aren't printing them since there is no format specifier being used here. Second, even if you were printing them at this stage they are uninitialized since you haven't read anything into them yet.




    Code:
    while ((fgets(fp1)!=EOF)
    {
    There are 3 open parenthesis here and only 2 closing parenthesis.




    Code:
    for(i=0,i<2500,i++)
    {
       for(j=0,j<5,j++)
    }
    You've forgotten some important elements of writing a proper for loop here.
    Salem likes this.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with error message: syntaz error befor "namespace"
    By missaln85 in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2012, 12:03 PM
  2. Error "in function 'main' syntax error before 'int' Help Please
    By blackhat11907 in forum C Programming
    Replies: 5
    Last Post: 08-20-2011, 07:05 PM
  3. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  5. need help?(have done c befor and new to C++)
    By Panzer_online in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2004, 09:44 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21