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); }
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...
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);
I have added the code block for you and you should start before the code with Code: and end it with [ /code]
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.
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...