Hello to all,
I am receiving a bus error when I run the following code:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct { char *name ; char *data ; int length ; int type ; } sequence ;
sequence loadedSequences[1000] ;
int nSequences = 0 ;
int main()
{
char buffer[1000] ;
char *command ;
char *filename, *list_num ;
for(;;)
{
printf("SeqTool> ") ;
fpurge(stdin) ;
fgets(buffer, 1000, stdin) ;
fpurge(stdin) ;
// Eliminating the newline character
char *p = strchr(buffer, '\n') ;
if (p)
{
*p = '\0' ;
}
command = strtok( buffer, " \t\n" ) ;
////////////////// Load sequence in FASTA format //////////////////////////
if( (strcmp ( command, "read" )) == 0 )
{
char *fileName ;
fileName = strtok(NULL, " \t\n" ) ;
FILE *input = fopen(filename, "r") ;
fgets( buffer, 1000, input) ;
char *seqName ;
seqName = &buffer[1] ; // After the > in FASTA format
loadedSequences[nSequences].name =
(char *) malloc( ( strlen(seqName) + 1 ) * sizeof( char ) ) ;
strcpy( loadedSequences[nSequences].name , seqName ) ;
++nSequences ;
}
What I am trying to do is read in from a standardized format (FASTA) and collect the data so that I can manipulate it later if needed. The syntax for the command should be:
SeqTool> read <filename>
Any help would be great.