|
-
October 26th, 2008, 01:25 PM
#1
Reading form file ANSI C function help
Hy everybody!
I am trying to make a function that reads data from a text file , from a specific position :
data looks like this :
04000040MAAS SECURITE SOCIETE DE SECURITE PRIVE
04000040MMARTIN ELSA RAPHAELLE
on two lines . I need lets say the names I have to go to a start position that I know my data is and get it ( I know the length)
My code is for the function :
void Get_Name(int start_pozition,int item_lenght, FILE *Nourea_file)/* Funtion who returns an item on a certain pozition on the imput file*/
{
char *read_Buffer;
char *c[100];
int j=1;
fgets(read_Buffer,1000,Nourea_file);
while(!feof(Nourea_file)){
fgets(read_Buffer, start_pozition,Nourea_file);
c[j]=(char *)malloc(item_lenght*sizeof(char));
strcpy(c[j],fgets(read_Buffer, item_lenght,Nourea_file));
j++;
fgets(read_Buffer, 1000,Nourea_file);
}
puts(c[1]);gectch() // for test purpose
}
When I try to increment the pointer array seams empty.
Please help I will appreciate it very much .
Thanks for you're answers !
Last edited by Valy18; October 26th, 2008 at 01:33 PM.
-
October 27th, 2008, 03:53 PM
#2
Re: Reading form file ANSI C function help
-
October 28th, 2008, 03:24 AM
#3
Re: Reading form file ANSI C function help
Hijacked this thread will not make you thread get better response.
No idea what you saying here.
Thanks for your help.
-
October 28th, 2008, 03:40 AM
#4
Re: Reading form file ANSI C function help
 Originally Posted by Valy18
Code:
void Get_Name(int start_pozition,int item_lenght, FILE *Nourea_file)/* Funtion who returns an item on a certain pozition on the imput file*/
{
char *read_Buffer;
char *c[100];
int j=1;
fgets(read_Buffer,1000,Nourea_file);
while(!feof(Nourea_file)){
fgets(read_Buffer, start_pozition,Nourea_file);
c[j]=(char *)malloc(item_lenght*sizeof(char));
strcpy(c[j],fgets(read_Buffer, item_lenght,Nourea_file));
j++;
fgets(read_Buffer, 1000,Nourea_file);
}
puts(c[1]);gectch() // for test purpose
}
When I try to increment the pointer array seams empty.
Please help I will appreciate it very much .
Thanks for you're answers !
char *c[100];
You have Acctually defined 100 pointers to char
fgets(read_Buffer, start_pozition,Nourea_file);
read_Buffer doesn't point to anything.
c[j]=(char *)malloc(item_lenght*sizeof(char));
Oh God. The memory!!!
Acctually I just noticed that theres a mistake in every line.
If you'r learning from a book; Nuke it from orbit, it's only way to be sure.
You just divided by zero, didn't you?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|