Logo F2FInterview

C Interview Questions

Q   |   QA

void PrintPermu (char *sBegin, char* sRest) {
     int iLoop;
     char cTmp;
     char cFLetter[1];
     char *sNewBegin;
     char *sCur;
     int iLen;
     static int iCount;
     iLen = strlen(sRest);

     if (iLen == 2) {
          printf("%d: %s%s\n",iCount,sBegin,sRest);
          printf("%d: %s%c%c\n",iCount,sBegin,sRest[1],sRest[0]);
     } else if (iLen == 1) {
          printf("%d: %s%s\n", iCount, sBegin, sRest);
     } else {
          // swap the first character of sRest with each of
          // the remaining chars recursively call debug print
          sCur = (char*)malloc(iLen);
          sNewBegin = (char*)malloc(iLen);
          for (iLoop = 0; iLoop <>
          strcpy(sCur, sRest);
          strcpy(sNewBegin, sBegin);
          cTmp = sCur[iLoop];
          sCur[iLoop] = sCur[0];
          sCur[0] = cTmp;
          sprintf(cFLetter, "%c", sCur[0]);
          strcat(sNewBegin, cFLetter);
          debugprint(sNewBegin, sCur+1);

void main() {
     char s[255];
     char sIn[255];
     printf("\nEnter a string:");
     PrintPermu(s, sIn);

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: