Hello Everyone,
I writing up a program for a class assignment that will create scrambled words by circularly rotating the middle characters of each word by 1 character. Place the scrambled words, 1 per line in an output file.
in my dict.txt file placed the following words
the output file for scramble.txt is the followingcomputer
dog
pepper
marker
teapot
the first issue i have is that i can't get to display the output file when i run the program and the scrambling is not working as intended. would i be able to get some help on perfecting this assignment. thanksctmpouer
odg
pepper
kaemrr
toaept
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> /* needed to use exit(1) */ char* scramble(char* str) { int i,m,k; for(i=1;i<(strlen(str)-1);i++) { m = rand() % (strlen(str)-1); k = rand() % (strlen(str)-1); if(m == k) { i--; continue; } char temp = str[k]; str[k] = str[m]; str[m] = temp; } return str; } main() { char word[80]; FILE *fpin; FILE *fpout; /* open the input file -- quit if not found */ fpin = fopen ("dict.txt", "r"); if (fpin == NULL) { printf("Memmory allocation failed."); exit(1); } /* open the output file */ fpout = fopen("scramble.txt", "w"); while (fscanf (fpin,"%[^\n]\n",word)==1) { fprintf (fpout,"%s\n", scramble(word)); } }