Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Where's the error? (C) (http://www.go4expert.com/forums/wheres-error-c-t7767/)

cquestion 9Dec2007 02:19

Where's the error? (C)
 
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);
}


Salem 9Dec2007 02:58

Re: Where's the error? (C)
 
Where is the 'while' which matches your 'do' ?

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

cquestion 9Dec2007 03:35

Re: Where's the error? (C)
 
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[i][j]);) != EOF), but it returns error...

cquestion 9Dec2007 03:38

Re: Where's the error? (C)
 
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);

shabbir 9Dec2007 12:04

Re: Where's the error? (C)
 
I have added the code block for you and you should start before the code with [code] and end it with [ /code]

Salem 9Dec2007 16:49

Re: Where's the error? (C)
 
How do you know how many lines/words there are in the file?

> char todos_fich[i][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.

cquestion 11Dec2007 06:09

Re: Where's the error? (C)
 
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...

Salem 11Dec2007 18:09

Re: Where's the error? (C)
 
I recently posted how to allocate a 2D array here
http://www.go4expert.com/showthread.php?t=7759


All times are GMT +5.5. The time now is 14:19.