I'm relatively a beginner in programming in C and am getting super confused with arrays and pointers.
Basically what I'm trying to do is extend a string that contains binary to the designated length len; (i.e. len=8 for num[]=101 would produce "00000101").
Can someone help me understand what's wrong with this?
const char * extendBinary(char num[], int len) {
char *number = #
int length = len;
int difference;
if(strlen(*num)<len) {
difference = len-strlen(num);
while(difference>0)
{
&number = strcat("0", &number);
difference--;
}
}
return number;
}
const. As for the arguments I'd recommend you to usesize_tfor sizes and lengths arguments, and for thenumargument you have to remember that all arrays decays to pointers so in the argument declarationchar num[]is the same aschar *num(howeverchar a[][X]is not the same aschar **a).char *number = #incomplete