Im trying to create a C program to create a small wordlist .txt file. I created char array of 10 elements, and I need every possible 4 letter combination of those 10 chars.
So, i figured to have 4 for loops inside each other to take elements from that array and create 4 letter combinations and write it to a .txt.
My problem is with using pointers to access elements of the array. I am doing:
char array[10] = {'A', 'S' ,'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M'};
char input[4];
char *p;
p=array;
FILE *pFile = NULL;
char *filename = "output.txt";
pFile = fopen(filename, "w");
for(i=0;i=3;i++) {
for(j=0;j=3;j++) {
for(k=0;k=3;k++) {
for(l=0;l=3;l++) {
strcpy(input, *(p+i));
strcat(input, *(p+j));//"gluing" first and second element of new string together
strcat(input, *(p+k));//same as line before
strcat(input, *(p+l));
strcat(input, "\n");
fprintf(pFile, input);
//end of for loops, closing .txt file etc.
This compiles nicely and terminal starts, but then crashes. I think its because of some error in accessing array elements.
Any ideas? Much appreciated!
Additional info> When I create:
char string[10] = "assd";
//and insert that instead of *(p+i) anywhere it works as it is supposed to
char array[10] = {A, S ,D, F, G, H, J, K, L, M};This compiles nicely...? Hard to believe...warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast; and/usr/include/string.h:127: note: expected ‘const char * restrict’ but argument is of type ‘char’… gcc even without any warning explicitly enabled.