-
Notifications
You must be signed in to change notification settings - Fork 1
/
filefuncs.c
47 lines (38 loc) · 1.13 KB
/
filefuncs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* File Functions implementation - filefuncs.c
* Created by: Shawn
*/
#include "filefuncs.h"
long int getStartPos(FILE *f) {
int ch;
long int sPos = -1L; //Initialize to error code
sPos = ftell(f);
for (ch = fgetc(f); ch != EOF && !isalpha((char) ch); ch = fgetc(f)) { //Only alphabetic letters allowed, no numbers.
sPos = ftell(f);
}
return sPos;
}
long int getEndPos(FILE *f) {
int ch;
long int ePos = -1L; //Initialize to error code
ePos = ftell(f);
for (ch = fgetc(f); ch != EOF && isalpha((char) ch); ch = fgetc(f)) { //Only alphabetic letters allowed, no numbers.
ePos = ftell(f);
}
return ePos;
}
char** shuffleWords(char** arrayOfWords, int wordCount)
{
time_t t;
srand((unsigned) time(&t));
for(int i = 0; arrayOfWords[i] != NULL; i++)
{
//FisherYates shuffle method
char* temp = arrayOfWords[i];
int r = rand() % wordCount; //Generate random number between 0 and wordCount - 1
arrayOfWords[i] = arrayOfWords[r];
arrayOfWords[r] = temp;
}
arrayOfWords[wordCount] = NULL;
return arrayOfWords;
}