I am having a bit of difficulty understanding the arguments for fscanf. The first two are self-explanatory. The first argument is the point file. It gets the content from this file. The second argument is the type of content in the file. In this case it's int so there is usage of %d. Now, the third argument, I am having difficulty discerning and it would help to have it done in some other way, so I can better understand what this 3rd argument is all about.
#include <stdio.h>
#include <string.h>
int main(void);
void getCode(char a[]);
int getMessage(int a[]);
void sortMessage(int a[], int b);
void decodeMessage(char a[], int b[], int c);
int main(void) {
// declare file names
char string[53];
int integers[27];
int msgSize;
// int codeSize = 52;
// Open files & there content
getCode(string);
msgSize = getMessage(integers);
sortMessage(integers, msgSize);
decodeMessage(string, integers, msgSize);
}
void getCode(char string[]) {
// get content from code file & print it
FILE *C = fopen("codefile.txt", "r");
while (fgets(string, 55, C)) {
printf("%s\n", string);
}
}
getMessage(int integers[]) {
// Get content from message file & return it
FILE *M;
M = fopen("msgfile.txt", "r");
int counter = 0;
/* Read one number at a time from the file and store it */
while (!feof(M)) {
fscanf(M, "%d", (integers + counter));
counter++;
}
/* Close the file */
// fclose(M);
return (counter);
}