Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void RecursivePermute(char str[], int k, FILE *fprt);
- void ExchangeCharacters(char str[], int i, int j);
- int main()
- {
- char str[10] = "";
- char word[10] = "" ;
- FILE *file = fopen("AssignmentThreeInput.txt", "r");
- FILE *fptr = fopen("AssignmentThreeOutput.txt", "w");
- if(file == NULL || fptr == NULL)
- printf("file not found");
- while(!feof(file))
- {
- fgets(str, 10 , file);
- strcpy(word, str);
- printf("working on word %s", word);
- printf("%d", h);
- system("pause");
- RecursivePermute(word, 0, fptr);
- }
- fclose(file);
- fclose(fptr);
- return;
- }
- void RecursivePermute(char str[], int k, FILE *fptr)
- {
- int j;
- // Base-case: All fixed, so print str.
- if (k == strlen(str))
- {
- fprintf(fptr, "%s\n", str);
- }
- else
- {
- // Try each letter in spot j.
- for (j = k; j < strlen(str); j++)
- {
- ExchangeCharacters(str, k, j);
- RecursivePermute(str, k + 1, fptr);
- ExchangeCharacters(str, j, k);
- }
- }
- }
- void ExchangeCharacters(char str[], int i, int j)
- {
- char temp = str[i];
- str[i] = str[j];
- str[j] = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement