CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    9

    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.

  2. #2
    Join Date
    Mar 2007
    Posts
    9

    Re: Reading form file ANSI C function help

    ..

  3. #3
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Croatia - Zagreb
    Posts
    459

    Re: Reading form file ANSI C function help

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured