Where's the error? (C)

Discussion in 'C' started by cquestion, Dec 8, 2007.

  1. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hello, i am doing a project and I have a problem with the compilation. It says me that before the penultimate " } " there's an error. Culd you help me to find it?
    Code:
    #include <stdio.h>
    #include <string.h>
    
    void leer(FILE *Elementos)
    {
         Elementos=fopen("elementos.txt", "r");
         int i=0, j=0; char todos_fich[i][2];
         do
         {
           for(j=0;j=1;j++)
           {
             fscanf(Elementos, "%s", todos_fich[i][j]);
           }
          i++;
         
         }
         fclose(elementos.txt);
    }
     
    Last edited by a moderator: Dec 9, 2007
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Where is the 'while' which matches your 'do' ?

    Also, use [code][/code] tags when posting code.
     
  3. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hello Salemn. Ok, i understand the problem. But i have a new one about it: i want to fill todos_fich with the character strings in elementos.txt. So what should i include in while ( )?. I have tried while (fscanf(Elementos, "%s", todos_fich[j]);) != EOF), but it returns error...
     
  4. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    I'm sorry, I fortot using
    Code:
    : the thing I write (and doesn't work) is
    [code] while (fscanf(Elementos, "%s", todos_fich[i][j]) !=EOF);
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I have added the code block for you and you should start before the code with
    Code:
     and end it with [ /code]
     
  6. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    How do you know how many lines/words there are in the file?

    > char todos_fich[2];
    Aside from the fact that i is zero at this point, this doesn't create an array you can just extend at will.

    > for(j=0;j=1;j++)
    Refer to your book for proper syntax. Say
    for(j=0;j<2;j++)

    > fclose(elementos.txt);
    This takes the file handle, Elementos as the parameter.

    Passing Elementos as a parameter does no good. You'll get the same effect by making it a local variable.
     
  7. cquestion

    cquestion New Member

    Joined:
    Oct 25, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hello Salem/shabbir , the problem is that I haven't text book for study. I am Spanish and the only book I have been told to buy is the one writed by "Kernich"(may be wrong writed, I don't remember the exact name). But that book isn't in Spanish language, and I have considered ordering it in English, but I'm afraid of missunderstand some words leading me to important missconceptions.

    Another think I'm interested in is that, as far as I know, matrixes are declared as, for example a matrix of inttegers:
    Code:
    int mat[10][20] 
    ; But I have some problems linking that way of declarations with the pointers way. I thing that
    Code:
     int *p=&mat 
    means
    Code:
    p=&mat[0]=&mat 
    . But if am referring to the pointer which contents the adress of
    Code:
    *p=&mat[0] 
    , what kind of pointer is? I mean , (kind of pointer)
    Code:
    *(*p) 
    . Also I have a second question: I think I could 'make' a matrix using those pointers, but I think that a matrix and a pointer to pointer of (kind of data) aren't the same thing, unlike what people and internet manuals usually say, because when I declare the matrix, I save a size of memory for my matrix, but if I do that with pointers...................¿Could their adress get mixed with other one's and give me problems?
    Note: The only solve I find is doing malloc when declaring the pointer. If I do that, can I assure that those pointer to pointers are exactly the same than matrixes?

    Thanks a lot, you help me so much...
     
  8. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice