here is more code to show what i am doing
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct { char *name ; char data[1000000] ; int length ; int type ; char header[1000] ; } 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] ;
char header_line[1000] ;
FILE *input, *output ;
char *seqName ;
char *command ;
char *filename ;
char *accession_id ;
int list_num ;
int i ;
int c ;
int n ;
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
strcpy( header_line, seqName ) ;
accession_id = strtok(header_line, " \n\t" ) ;
loadedSequences[nSequences].name =
(char *) malloc( ( strlen(accession_id) + 1 ) * sizeof( char ) ) ;
strcpy(loadedSequences[nSequences].header, seqName) ;
strcpy( loadedSequences[nSequences].name , accession_id ) ;
// Collect the sequence from FASTA file
n = 0 ;
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 ;
}
///////////////// Write sequence in FASTA format //////////////////////////
else if ((strcmp ( command, "write")) == 0 )
{
list_num = atoi(strtok(NULL, " \n\t")) ;
filename = strtok(NULL, " \n\t") ;
output = fopen(filename, "w") ;
fputs(loadedSequences[list_num].header, output) ;
fputs(loadedSequences[list_num].data, output) ;
fclose(output) ;
}
what i am trying to do is take the data that was read in from a file and stored, and write out to a different file. the data is stored in loadedSequences[nSequences].data and loadedSequences[nSequences].header