#include <stdio.h>

int main(){ 

	char *names[1024];
	float *rates[20];

	FILE* file;
	file = fopen("tecaji.txt","r");

	while(!feof(file)){
		fscanf(file, "%s", &names);
		for(int i = 0; i < 20; i++){
			fscanf(file, "%f", &rates);
		}
	}

	for(int a = 0; a < 50; a++){
		printf("%s", names[a]);
	}

}

The file contents look like this: String Float Float Float ... 20 Float's after
each string.

March 3.56 24.3 2.5 67.4....
April 4.53 5.3 46....

Anyways i am reading the file no problems there and i want to add strings to names
table and numbers to rates table simple.. For now i wish to use two tables instead
of a two dimensional table.

But i have a problem i am writing in Pelles C keeps giving me error that
it's expecting char * but finding char **

for line 13 your compiler is correct. names is an array of 1024 pointers, which are unallocated, meaning they point to no memory. You will have to allocate memory for them before they can be used. An easier way to do this for your program is to just hardcode the memory on line 7 char names[1024][40]; This allocates memory for 1024 names, each name can be up to 40 characters. That should be more than enough for your program.

Then on line 10 you have to index into names array using the loop counter, fscanf(file,"%s", names[i]); Now line 15 is something like line 10. On line 7 remove the * so that it allocates 20 floats, not 20 pointers. Then on line 15 do this: fscanf(file,"%f", &rates[i]);

Edited 5 Years Ago by Ancient Dragon: n/a

Ancient Dragon> char names[1024][40]; This allocates memory for 1024 names, each name can be up to 40 characters. That should be more than enough for your program.

OP explained already that s[he] did not wanted to do it as such.

nered> For now i wish to use two tables instead
of a two dimensional table.

char *names[1024]; /* array of pointers; they can only hold addresses in memory, not strings like names  would be */

If you don't want to use multidimensional arrays you have to learn how to allocate dynamic memory.

while(!feof(file)){

That's never a good way of controlling a loop. feof() will not produce the wanted result, and most likely will loop one time more than expected by the naive.
More about it

Explicitly return in main.

Wow thanks both of you. Dragon that solved my problem and Aia thanks for the pointers
i always wondered why i get an extra empy line when reading a file.

I didn't know you can make a table like:
char table[number of entries][max length of each entrie];

I imagined a multidimensional table in C like a HashMap in Java or Array in
PHP or dictionary in Python.

I imagined if i do: char table[][];

I meant: char table[ keys ][ values ]..

Wow thanks both of you. Dragon that solved my problem and Aia thanks for the pointers
i always wondered why i get an extra empy line when reading a file.

I didn't know you can make a table like:
char table[number of entries][max length of each entrie];

I imagined a multidimensional table in C like a HashMap in Java or Array in
PHP or dictionary in Python.

I imagined if i do: char table[][];

I meant: char table[ keys ][ values ]..

No exactly!
You could have char xyz[x][y][z] Now that you got a little further, keep this in mind.

FILE* file;

file = fopen("tecaji.txt","r");

Always check for the successful return of a function if it was designed for it.
Otherwise, the assumption can and will break your program.

FILE* file;

file = fopen("tecaji.txt","r");
if (file != NULL) {
    /* do what you intended to do with it */
}

Ancient Dragon> char names[1024][40]; This allocates memory for 1024 names, each name can be up to 40 characters. That should be more than enough for your program.

OP explained already that s[he] did not wanted to do it as such.

Oh really??? Where was that mentioned?

For now i wish to use two tables instead of a two dimensional table.

You must have misunderstood that statement. By two tables he meant names[] and rates[].

Edited 5 Years Ago by Ancient Dragon: n/a

Oh really??? Where was that mentioned?

You must have misunderstood that statement. By two tables he meant names[] and rates[].

That became irrelevant two posts ago, Ancient Dragon. Take the thanks from the OP and the one point you got for it, and be happy.

Edited 5 Years Ago by Aia: Because I can

This article has been dead for over six months. Start a new discussion instead.