Still not able to get data.
Here is my code again with the declarations:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct { char *name ; char data[1000000] ; int length ; int type ; } sequence ;
sequence loadedSequences[1000] ;
int nSequences = 0 ;
int main()
{
char std_input[1000] ; // prev. buffer
char header_data[1000] ;
char seq_data[100000] ;
char buffer[100000] ;
FILE *input ;
char *seqName ;
char *command ;
char *filename, *list_num ;
int i = 0 ;
int c ;
int n = 0 ;
for(;;)
{
printf("SeqTool> ") ;
fgets(std_input, 1000, stdin) ;
fpurge(stdin) ;
// Eliminating the newline character
char *p = strchr(std_input, '\n') ;
if (p)
{
*p = '\0' ;
}
command = strtok( std_input, " \t\n" ) ;
////////////////// Load sequence in FASTA format //////////////////////////
if( (strcmp ( command, "read" )) == 0 )
{
filename = strtok(NULL, " \t\n" ) ; // collect filename
if( filename )
{
input = fopen(filename, "r") ;
if ( !input )
{
perror(filename);
continue ;
}
}
fgets( header_data, 1000, input) ;
seqName = &header_data[1] ; // After the > in FASTA format
loadedSequences[nSequences].name =
(char *) malloc( ( strlen(seqName) + 1 ) * sizeof( char ) ) ;
strcpy( loadedSequences[nSequences].name , seqName ) ;
// Collect the sequence from FASTA file
while (c = getc(input) != EOF)
{
if(c >= 'A' && c <= 'Z')
{
loadedSequences[nSequences].data[n++] = c ;
}
}
loadedSequences[nSequences].length = strlen((loadedSequences[nSequences].data)) ;
fclose(input) ;
++nSequences ;
}