#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char print_two(char *reg, char *s)
{
int i, l_s = (int) strlen(s), l_reg = (int) strlen(reg);
for(i = 0; i < l_reg; i++)
{
printf("\n %c \n", reg[i]);
}
return 0;
}
int main(void)
{
char reg;
printf("Give a rule: ");
scanf("%s", ®);
char s;
printf("Give a string: ");
scanf("%s", &s);
print_two(®, &s);
return 0;
}
Program start:
Give a rule: qwert
Give a string: asdf
result:
d
q
a
s
d
f
How I can avoid overwrite reg
by s
?
I tried with realloc, malloc - 0 effect.
Two variables should be dynamic.
Is it possible to do?
user give 55 chars -> array 55
user give 100 chars -> array 100