My problem is that I can't return the processed string to the function. The function's job is that it must accept a string, change its letters, and return the processed string to the function.
char *dna_strand(const char *dna)
{
int a;
for (a = 1; *(dna+a) != '\0' ; a++) {
}
char array[a];
for (int i = 0; i < a; ++i) {
if ('A' == *(dna + i)) {
array[i] = 'T';
} else if ('T' == *(dna + i)){
array[i] = 'A';
} else{
array[i] = *(dna + i);
}
}
return array;
}
Error : [1]: https://i.sstatic.net/uwvCh.png
strlen() + 1instead of the first loop.VLAis anC99extension and shall be avoided. Better useallocainstead ofarray[i]or in your case,mallocthen return the allocated string, but then you must free it.allocawould not work as op wants to return the value.