how to store it

This is a discussion on how to store it within the C Programming forums, part of the General Programming Boards category; Code: file: >chromosome01 CTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAA CCCTAAACCCTAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACAGCT GACAGTACGATAGATCCACGCGAGAGGAACCGGAGAGACAACGGGATCCAGGCGCCAGCG ACGGATCCGGGCGAGAGGGGAGTGGAGATCATGGATCCGTGCGGGAGGGGAAGAAGTCGC CGAATCCGACCCTCCCATCGCCATCGACAGTAGGTCTGCGCGAGAGGGGCACCGGCGCTG >chromosome02 GCTCTGAGCGAGATGCAACGCCGGCCGGCTTGGAGAGTAACTCAAGAGAGACAGAATGGA AGATAGAGAACAAGAGAGTGAGAGGATAAGGATATAGACCAGACCACACAATTTTCTCTT CTTTTTAACTTTGTATTAAGATCTTTTATGGAACATCTTTTATTGTTGATATCAAAATAA CTGAAACTTATACTTTAATATTTTTTGAGACAAAAAGTAACAATCGTAAAAAAAAGTTCC >chromosome03 ACGAGAGTTACCCCACCACCCATGTCTCGAGCCGACCAGATCTGCCGCCCACGACCCGAG TCATCGTTGGATCCACCACCCACAACCCGCGACCGAGCTACGCCTCCTGTGGATTGATGC CACTGCCCTGAGCTTCACTGCCGGTACTGTCGCTCGCGACCCGAGCTCCGCCGCTGGTAC CGTCGCCCACAACTCAAGCTGTGTTGCCACTAGAGAAAAAGGAGGCGAGAGCGAGGGCAA Aiming at ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how to store it

    Code:
    file:
    
    >chromosome01
    CTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAA
    CCCTAAACCCTAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACAGCT
    GACAGTACGATAGATCCACGCGAGAGGAACCGGAGAGACAACGGGATCCAGGCGCCAGCG
    ACGGATCCGGGCGAGAGGGGAGTGGAGATCATGGATCCGTGCGGGAGGGGAAGAAGTCGC
    CGAATCCGACCCTCCCATCGCCATCGACAGTAGGTCTGCGCGAGAGGGGCACCGGCGCTG
    >chromosome02
    GCTCTGAGCGAGATGCAACGCCGGCCGGCTTGGAGAGTAACTCAAGAGAGACAGAATGGA
    AGATAGAGAACAAGAGAGTGAGAGGATAAGGATATAGACCAGACCACACAATTTTCTCTT
    CTTTTTAACTTTGTATTAAGATCTTTTATGGAACATCTTTTATTGTTGATATCAAAATAA
    CTGAAACTTATACTTTAATATTTTTTGAGACAAAAAGTAACAATCGTAAAAAAAAGTTCC
    >chromosome03
    ACGAGAGTTACCCCACCACCCATGTCTCGAGCCGACCAGATCTGCCGCCCACGACCCGAG
    TCATCGTTGGATCCACCACCCACAACCCGCGACCGAGCTACGCCTCCTGTGGATTGATGC
    CACTGCCCTGAGCTTCACTGCCGGTACTGTCGCTCGCGACCCGAGCTCCGCCGCTGGTAC
    CGTCGCCCACAACTCAAGCTGTGTTGCCACTAGAGAAAAAGGAGGCGAGAGCGAGGGCAA
    Aiming at the file content above,I want to use pointer array to store it
    Code:
        FILE *fp;
        fp = fopen("file1","r"); 
        char *pa[12];
        char *tmp;
        if(str[0] == '>')
            {
                
                      j = 0;
                      chr_num++;//chromosome count         
                
            }else{
    
                 //format str  remove the last spaces 
                 sscanf(str,"%s",tmp);
                 
                 //combine sequcences
                  while(*tmp++ != '\0')
                  {
                        // i++;
                         *(pa[chr_num]+j++) = *tmp;
                               
                  }
                  
            }
             
        } 
        fclose(fp);
    data structure image:
    http://202.127.18.228/s.jpg
    Last edited by zcrself; 08-17-2009 at 11:56 PM.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    Quote Originally Posted by zcrself View Post
    Code:
    file:
    
    >chromosome01
    CTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAA
    CCCTAAACCCTAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACAGCT
    GACAGTACGATAGATCCACGCGAGAGGAACCGGAGAGACAACGGGATCCAGGCGCCAGCG
    ACGGATCCGGGCGAGAGGGGAGTGGAGATCATGGATCCGTGCGGGAGGGGAAGAAGTCGC
    CGAATCCGACCCTCCCATCGCCATCGACAGTAGGTCTGCGCGAGAGGGGCACCGGCGCTG
    >chromosome02
    GCTCTGAGCGAGATGCAACGCCGGCCGGCTTGGAGAGTAACTCAAGAGAGACAGAATGGA
    AGATAGAGAACAAGAGAGTGAGAGGATAAGGATATAGACCAGACCACACAATTTTCTCTT
    CTTTTTAACTTTGTATTAAGATCTTTTATGGAACATCTTTTATTGTTGATATCAAAATAA
    CTGAAACTTATACTTTAATATTTTTTGAGACAAAAAGTAACAATCGTAAAAAAAAGTTCC
    >chromosome03
    ACGAGAGTTACCCCACCACCCATGTCTCGAGCCGACCAGATCTGCCGCCCACGACCCGAG
    TCATCGTTGGATCCACCACCCACAACCCGCGACCGAGCTACGCCTCCTGTGGATTGATGC
    CACTGCCCTGAGCTTCACTGCCGGTACTGTCGCTCGCGACCCGAGCTCCGCCGCTGGTAC
    CGTCGCCCACAACTCAAGCTGTGTTGCCACTAGAGAAAAAGGAGGCGAGAGCGAGGGCAA
    Aiming at the file content above,I want to use pointer array to store it
    Code:
        FILE *fp;
        fp = fopen("file1","r"); 
        char *pa[12];
        char *tmp;
        if(str[0] == '>')
            {
                
                      j = 0;
                      chr_num++;//chromosome count         
                
            }else{
    
                 //format str  remove the last spaces 
                 sscanf(str,"%s",tmp);
                 
                 //combine sequcences
                  while(*tmp++ != '\0')
                  {
                        // i++;
                         *(pa[chr_num]+j++) = *tmp;
                               
                  }
                  
            }
             
        } 
        fclose(fp);
    data structure image:
    http://202.127.18.228/s.jpg
    That code doesn't make much sense. Why don't you post a compilable program? Also, you need to allocate some memory to 'pa' - 12 pointers still == 0 available memory. Ditto for 'tmp'.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Sebastiani View Post
    That code doesn't make much sense. Why don't you post a compilable program? Also, you need to allocate some memory to 'pa' - 12 pointers still == 0 available memory. Ditto for 'tmp'.
    how to allocate some memory to 'pa'?
    char *pa[12] = (char *) malloc( 10000000);

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    For a single pointer:

    Code:
    char *p = malloc(n);
    For many:

    Code:
    char *pa[] = 
    {
          malloc(n), 
          malloc(n), 
          malloc(n), 
          malloc(n), 
          malloc(n)
    };
    All that could be done in a loop, of course. And don't forget to free() what you malloc(). Also, it might be a good idea to read up on pointers as much as possible at this point.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Sebastiani View Post
    For a single pointer:

    Code:
    char *p = malloc(n);
    For many:

    Code:
    char *pa[] = 
    {
          malloc(n), 
          malloc(n), 
          malloc(n), 
          malloc(n), 
          malloc(n)
    };
    All that could be done in a loop, of course. And don't forget to free() what you malloc(). Also, it might be a good idea to read up on pointers as much as possible at this point.
    I see!

    Using of pointer is very difficult!
    Do you have some books about introduction of pointers of C or C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 02:55 AM
  2. Free Store of memory
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2007, 01:27 PM
  3. store data from ifstream and store in link list
    By peter_hii in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2006, 08:50 AM
  4. Do you store store one off data arrays in a class?
    By blood.angel in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2002, 12:05 PM
  5. how to store a node on hard disk
    By ALLRIGHT in forum C Programming
    Replies: 3
    Last Post: 05-13-2002, 10:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21