WHEN I TRY TO OPEN FILE IN APPEND MODE ,IT CREATES THE FILE BUT IT SAYS "IN-VALID ENCODING " ALONG WITH THE FILE-NAME ........I HAVE PASSED THE ARRAY OF STRINGS CORRECTLY IN string moreover the strings in "string" are sorted .....any string in "string" is made up of only 4 characters "A","G","T","C".
#include <malloc.h>
#include"check_duplication_write.h"
int check_duplication_write(int *no_of_strings,char *file_name,char **string){
char *dest;
int i,result;
int temp_length=LENGTH-FIRSTCHARACTERS;//no need of writing a null character in the file
char temp[temp_length];
dest=(char *)malloc(1024*1024*1024);
char result_files[FIRSTCHARACTERS+5];
for(i=0;i<(*no_of_strings-1);++i){
if(!strncmp(string[i],string[i+1],FIRSTCHARACTERS)){
//the two adjacent strings have first four characters same
if(strcmp(string[i],string[i+1])){
//the two adjacent string are not exactly same
strncpy(temp,string[i]+FIRSTCHARACTERS,temp_length);
strcat(dest,temp);
}
}else{}//bypass if we find adjacent string exactly same
}else{
//writing to the file should be done here.
strcpy(result_files,"");
strncpy(result_files,string[i],FIRSTCHARACTERS);
//strcat(result_files,"\0");
strcat(result_files,".txt");
FILE *intermediate_files=fopen(result_files,"a");
fwrite(dest,strlen(dest),1,intermediate_files);
fclose(intermediate_files);
free(dest);
dest=(char *)malloc(1024*1024*1024);
}
}
free(dest);
return result;
}