An encoded file will be decoded by the program using a key input from the user. This key is a sequence of numbers that will scramble the message in the file into its appropriate order.
I have to use linked lists for this. I already started it, but I can't seem to find a correct way to jumble the words and display them correctly.
#include <stdio.h>
#include <string.h>
typedef struct _node_{
char word[30];
struct _node_ *pPtr_word;
}node_t;
int main(void)
{
FILE *pInput, *pOutput;
int a, b, count, num, group_num, counter, data[10], i, j;
node_t node[100];
node_t *pPtr;
pInput=fopen("input.txt","r");
if(pInput==NULL){
printf("Error: can't open file.\n");
return 1;
}
else{
if('\n')
count=count++;
for(a=0;a<count+1;a++)
fgets(node[a].word,30,pInput);
for(b=0;b<count+1;b++)
printf("%s\n", node[b].word);
}
printf("Enter number of numbers for key sequence: ");
scanf("%d", &num);
printf("Enter key sequence: ");
for(counter=0;counter<num;counter++)
scanf("%d", &data[counter]);
group_num=((count+1)/num);
for(i=0;i<group_num;i++)
for(j=0,pPtr=node;j<num-1;j++,pPtr++)
node[(data[j]-1)+num*i].pPtr_word=&node[...
pPtr->pPtr_word=NULL;
for(pPtr->word;pPtr!=NULL;pPtr=pPtr->pPt...
printf("%s", pPtr->word);
getchar();
getchar();
return 0;
}
Example, the file input [from a text file] is-- brown quick The over jumped fox dog. lazy the
Then the key sequence entered would be 321
The output should be-- The quick brown fox jumped over the lazy dog.
In my text file, it looks like this:
brown
quick
The
over
jumped
fox
dog.
lazy
the
Also, for displaying my linked list, it seems like it doesn't traverse the whole thing. I also can't seem to create the right formula to get the correct sequence [since there can be 2 or 4 numbers for the sequence and it should work for all cases].
Please help me out :)