This is the program to print all possible combination of the string. It was orginally written in C++.
Now i'm trying to write it in C but stuck with this problem of strings and pointers + some warnings.
INPUT is taken from argument, which is "const **char" .
I tried to allocate the memory too but its of no use at all. :|

# include <string.h>
# include <stdio.h>
# include <stdlib.h>

long fac(int n) {
    long f;
    for(f=1; n>1; n--) f*=n;
    return f;

int swap(char *tekst, int pos, int npos){
    char tmpchr=tekst[pos];
    return 0;

int findcombo(char *tekst, int pos){
    char *tmpstr;
    int counter=1;
    int npos=pos;
    int fact=fac(strlen(tekst)-pos);
    while(counter<=fact) {
        if(pos<(strlen(tekst)-1)) pos++;
            swap(tekst, npos, pos);
        else {
            printf("%s\n", tekst);
    return fact;

int main (int argc, char const* argv[])
    if(argc==0) {
        printf("Error: missing argument, string \n");
        return 1;

    int len=strlen(argv[1]);
    printf("Combination: %ld\n", fac(len));
/*  char *test=calloc(sizeof(char), len+1);*/
/*  printf("%d",sizeof(test));*/
/*  strcpy(test, argv[1]);*/
/*  printf("<%s>\n", test);*/
/*  free(test);*/
    return 0;

This may miss the prblem but...

/* printf("%d",sizeof(test));*/

sizeof is a snare and delusion! It is evaluated by the compiler and in this case will tell you that test is pointer.
Sizeof does not look at what is pointed at.... use strlen...

Hope this is some help.

You are rite but, but not quite rite, I was just testing it ! its in comment!

You never defined tmpstr except as a pointer. There is no storage space associated. Therefore
strcpy(tmpstr,tekst); copies into never-never-land, and therefore blows up.

This question has already been answered. Start a new discussion instead.