I am trying to get substrings from a string (a=ATCG) and then store it in an array but I am getting a warning: assignment makes integer from pointer without a cast [enabled by default] dna[i]=dna1;
I want the output array to print: ATCG TCG CG G
I am new to C, how do I fix this?
Here's my program
int main()
{
char a[]="ATCG", dna[20], *dna1 ;
dna1 = (char *)malloc(2000);
int i, len_of_seg_2;
for(i = 0; i < strlen(a); i++)
{
len_of_seg_2=strlen(a)-i+1;
strncpy(dna1, a+i, len_of_seg_2);
dna1[len_of_seg_2-1]='\0';
dna[i]=dna1;
printf("sequence:%s\n",dna1);
}
for(i=0;i<5;i++){
printf("\nseq:%s\n",dna[i]);
}
return 0;
}
dna1ischar *,dna[i]ischar. The error is exactly what it says. You are assigning a pointer to an integer value. Maybe you meantdna[i] = *dna1? Also, remember tofree(dna1)for good practice.dna[i]=dna1;? Are you trying to copy a single character, or a string. If you are trying to copy a string, then why is the destination (dna[i]) a character?