I'm trying to fill a string with the contents of the string for the size of another string. Problem is it will only copy the first element, how can I make it copy the whole string?
Code:
char a = "string A. Hello. World!";
char b = "help";
1.
Code:
memset(b, *b, strlen(a));
puts(b);
2.
Code:
for(i=0;i<strlen(a)-1;i++){
memset(b, b[i], strlen(a));
if(i==strlen(b)-1 && strlen(a)!=strlen(b)) i=0;
}
puts(b);
3. Also tried this.
Code:
char bNew[256]=" ";
int j=0;
for(i=0;i<strlen(a);i++){
bNew[i]=b[j];
if(j==strlen(b)-1) j=0;
if(i==strlen(a))bNew[i]='\0';
}
puts(b);
}
Output 1&2:
Output 3:
Desired output is:
Code:
helphelphelphelphelph