I'm currently working on an assignment and this have had me stuck for hours. Can someone please help me point out why this isn't working for me?
struct book
{
char title[25];
char author[50];
char subject[20];
int callNumber;
char publisher[250];
char publishDate[11];
char location[20];
char status[11];
char type[12];
int circulationPeriod;
int costOfBook;
};
void PrintBookList(struct book **bookList)
{
int i;
for(i = 0; i < sizeof(bookList); i++)
{
struct book newBook = *bookList[i];
printf("%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d\n",newBook.title, newBook.author, newBook.subject,
newBook.callNumber,newBook.publisher, newBook.publishDate, newBook.location, newBook.status,
newBook.type,newBook.circulationPeriod, newBook.costOfBook);
}
}
void GetBookList(struct book** bookList)
{
FILE* file = fopen("book.txt", "r");
struct book newBook[1024];
int i = 0;
while(fscanf(file, "%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d",
&newBook[i].title, &newBook[i].author, &newBook[i].subject,
&newBook[i].callNumber,&newBook[i].publisher, &newBook[i].publishDate,
&newBook[i].location, &newBook[i].status,
&newBook[i].type,&newBook[i].circulationPeriod, &newBook[i].costOfBook) != EOF)
{
bookList[i] = &newBook[i];
i++;
}
/*while(fscanf(file, "%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d",
&bookList[i].title, &bookList[i].author, &bookList[i].subject,
&bookList[i].callNumber, &bookList[i].publisher, &bookList[i].publishDate,
&bookList[i].location, &bookList[i].status, &bookList[i].type,
&bookList[i].circulationPeriod, &bookList[i].costOfBook) != EOF)
{
i++;
}*/
PrintBookList(bookList);
fclose(file);
}
int main()
{
struct book *bookList[1024];
GetBookList(bookList);
}
I get no errors or warnings on compile
it should print the content of the file, just like it is in the file.
Like this:
OperatingSystems Internals and Design principles;William.S;IT;741012759;Upper Saddle River;2009;QA7676063;Available;circulation;3;11200
Communication skills handbook;Summers.J;Accounting;771239216;Milton;2010;BF637C451;Available;circulation;3;7900
Business marketing management:B2B;Hutt.D;Management;741912319;Mason;2010;HF5415131;Available;circulation;3;1053
Patient education rehabilitation;Dreeben.O;Education;745121511;Sudbury;2010;CF5671A98;Available;reference;0;6895
Tomorrow's technology and you;Beekman.G;Science;764102174;Upper Saddle River;2009;QA76B41;Out;reserved;1;7825
Property & security: selected essay;Cathy.S;Law;750131231;Rozelle;2010;D4A3C56;Available;reference;0;20075
Introducing communication theory;Richard.W;IT;714789013;McGraw-Hill;2010;Q360W47;Available;circulation;3;12150
Maths for computing and information technology;Giannasi.F;Mathematics;729890537;Longman;Scientific;1995;QA769M35G;Available;reference;0;13500
Labor economics;George.J;Economics;715784761;McGraw-Hill;2010;HD4901B67;Available;circulation;3;7585
Human physiology:from cells to systems;Sherwood.L;Physiology;707558936;Cengage Learning;2010;QP345S32;Out;circulation;3;11135
bobs;thomas;IT;701000000;UC;1006;QA7548;Available;Circulation;7;5050
but when I run it, it outputs this:
OperatingSystems;;;0;;;;;;0;0
Internals;;;0;;;;;;0;0
and;;;0;;;;;;0;0
Design;;;0;;;;;;0;0
principles;William.S;IT;741012759;Upper;41012759;Upper;;0;;;;;;0;0
Saddle;;;0;;;;;;0;0
River;2009;QA7676063;Available;circulation;3;11200;lable;circulation;3;11200;;0;;;;;;0;0
Communication;;;0;;;;;;0;0
Thanks in advance, you're a life saver
I think your problem is that your fields contain spaces. fscanf will stop scanning a string (%s) when it sees a white space character. You need to change your %s format specifiers to allow spaces to be included. You can either just exclude your delimiter, e.g. %[^;] or specify what characters to include, e.g. %[ a-zA-Z0-9-] (I think I'd probably go for the first option).
% man fscanf
Not the cause, but in your PrintBookList method, you have
for(i = 0; i < sizeof(bookList); i++)
but you can't get the size of an array of structs that way (it returns 4, the size of a pointer).
It is standard practice to pass the size in:
void PrintBookList(struct book **bookList, int numBooks)
Don't forget to limit size of read strings (don't forget they end with a '\0' symbol) (scanf doesn't know how long the fields are).
scanf("%24[^;],...
Related
I'm getting an infinite running programm when I use the following code to read a string from keyboard and save it within a structured vector.
scanf("%s", strk_zgr_fp->bezeichnung, (int)sizeof(strk_zgr_fp->bezeichnung - 1));
Simply nothing happens after this line is reached and the program runs infinitly.
I know scanf() isn't recommended. We're using it only within our C beginners course and I want you to keep it in mind, ie please don't recommend other function rather than above mentioned for the moment.
Any help is much appreciated, thanks in advance.
#include <stdio.h>
typedef struct {
int nummer;
char bezeichnung;
int menge;
float preis;
} artikel;
void eingabe_artikel(artikel *strk_zgr_fp, int i_fp);
void ausgabe_artikel(artikel *strk_zgr_fp, int i_fp);
void main(void) {
artikel artikelliste[10];
artikel *strk_zgr;
int anzahl;
do {
printf("Bitte eine #Artikel eingeben [<= 10]: ");
scanf("%d", &anzahl);
if(anzahl < 1 || 10 < anzahl)
printf("\nEs wurde eine falsche #Artikel eingegeben.");
} while(anzahl < 1 || 10 < anzahl);
for(int i = 0; i < anzahl; i++)
eingabe_artikel(&artikelliste[i], i);
int i;
for(strk_zgr = artikelliste, i = 0; strk_zgr < artikelliste + anzahl;
strk_zgr++, i++)
ausgabe_artikel(strk_zgr, i);
}
void eingabe_artikel(artikel *strk_zgr_fp, int i_fp) {
printf("\nBitte den %d. Artikel eingeben: ", ++i_fp);
printf("\nNummer: ");
scanf("%d", &strk_zgr_fp->nummer);
printf("Bezeichnung: );
scanf("%s", strk_zgr_fp, (int)sizeof(strk_zgr_fp->bezeichnung - 1)); /* <-- */
printf("Menge: ");
scanf("%d", &strk_zgr_fp->menge);
float preis;
printf("Preis: );
scanf("%f", &preis);
strk_zgr_fp->preis = preis;
}
void ausgabe_artikel(artikel *strk_zgr_fp, int i_fp) {
printf("\n%d. Artikel: ", ++i_fp);
printf("\nNummer:\t%d", strk_zgr_fp->nummer);
printf("\nBezeichnung:\t%s", strk_zgr_fp->bezeichnung);
printf("\nMenge:\t%d", strk_zgr_fp->menge);
printf("\nPreis:\t%.2f EUR\n", strk_zgr_fp->preis);
}
NetBeans Version
Complier Version
Many problems in the code. Please at least fix the missing ending quotes on the printf() calls.
Now to the beef:
1) Your structure is wrong. 'Bezeichnung' is defined as a single character, not a string.
typedef struct {
int nummer;
char bezeichnung[100];
int menge;
float preis;
} artikel;
2) You cannot use scanf() in the way you did. If you want to limit the input length (which always is a good idea), you need to pass the maximum length into the format string.
Do you nee to use scanf()?? Because it gets messy from here on....
As your maximum input length might be variable or subject to change (see 1.), you need to build the format string for scanf. Something like this:
char format_str[15];
format_str[0] = '%';
//Dont use itoa(), it is not C standard.
sprintf(&format_str[1], "%d", (int)sizeof(strk_zgr_fp->bezeichnung) - 1);
strcat(format_str, "s");
scanf(format_str, strk_zgr_fp->bezeichnung);
Hope that gets you going.
PS: You need to include string.h for strcat().
I tried it out and it worked fine for me. Not sure on this sprintf() function. Could you please explain why I'm supposed to use it? By now, I used this code: char format_str[20]; format_str[0] = '%'; strcat(format_str, "s"); printf("Bezeichnung: "); scanf(format_str, strk_zgr_fp->bezeichnung);
While that works, you are missing out on limiting the length of the user's input. That is why I proposed using sprintf() to create a (sub)string containing the maximal allowable length of the user input, depending on how large your 'bezeichnung' is defined in the struct. Suppose 'bezeichnung' has a limit of 100 characters, you would want to limit the input to 99 (+1 for the zero-termination), so you want a scanf format string like this: "%99s".
chux has provided a much more compact version of my three lines, but I think, in the beginning, you will have it easier to just assemble such format strings piece by piece, at the same time learning how to a) change individual characters in a string, how to use sprintf() in a basic way, and how to concatenate strings with strcat().
There was another example which I did and the course leader provided a scanf() function like this to read a string: scanf("%s", &(strk_zgr_fp->bezeichnung));. I thought when I'm reading a string the address operator isn't used. The only difference is the address operator now is used and the element was put into brackets.
Now, I think this is bad practice. It works, but is superfluous. Consider this small code snippet:
#include <stdio.h>
#include <stdlib.h>
struct test{
int i;
char a_str[10];
};
int main()
{
struct test a_test;
printf("Normal array adress taking: %p\n", a_test.a_str);
printf("Using '&' to take adress of array: %p\n", &(a_test.a_str));
return 0;
}
Hope that helps.
Alright I've been at this all day and can't for the life of me get this down, maybe you chaps can help. I have a file that reads as follows
1301,105515018,"Boatswain","Michael R.",ABC, 123,="R01"
1301,103993269,"Castille","Michael Jr",ABC, 123,="R03"
1301,103993267,"Castille","Janice",ABC, 123,="R03"
1301,104727546,"Bonczek","Claude",ABC, 123,="R01"
1301,104731479,"Cruz","Akeem Mike",ABC, 123,="R01"
1301,105415888,"Digiacomo","Stephen",ABC, 123,="R02"
1301,106034479,"Annitto Grassis","Susan",ABC, 123,="R04"
1301,106034459,"Als","Christian",ABC, 123,="R01"
And here is my code...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NAME 15
#define MAX_SUBSEC 3
#define N 128
//void printArr(struct *students);
struct student{
int term;
int id;
char lastname[MAX_NAME];
char firstname[MAX_NAME];
char subjectname[MAX_SUBSEC];
int catalog;
char section[MAX_SUBSEC];
}students[10];
int main(){
int term;
int id;
char lastname[MAX_NAME];
char firstname[MAX_NAME];
char sub[MAX_SUBSEC];
int cat;
char sec[MAX_SUBSEC];
char fname[N];
FILE *inputf;
printf("Enter the name of the text file: ");
scanf("%123s",fname);
strcat(fname,".txt");
inputf = fopen(fname,"r");
if (inputf == NULL){
printf("I couldn't open the file for reading.\n");
exit(0);
}
//TROUBLE HERE!
fscanf(inputf, "%d,%d,%[^,]s", &students[0].term, &students[0].id,students[0].lastname);
printf("%d\n", students[0].term);
printf("%d\n", students[0].id);
printf("%s\n", students[0].lastname);
/*for (j = 1 ; j <= 10-1 ; j++){
for(k = 0 ; k <= 10-2 ; k++){
if(students[k] > students[k+1]){
temp = students[k];
students[k] = students[k+1];
students[k+1] = temp;
}
}
}*/
fclose(inputf);
system("pause");
return 0;
}
void printArr(int a[], int tally){
int i;
for(i = 0 ; i < tally ; i++){
printf("%d ", a[i]);
}
printf("\n");
}
My objective is to take each one of those values in the text file and input it to where it belongs in the struct and subsequently the struct array, but I can't get passed the first 2 ints.
Getting the lastname string, because it is a max of 15 characters, it spills over into the first name string right after it and takes what remaining characters it needs in order to fill up the lastname char array. Obviously I do not want this. As you can see I have tried strtok but it doesnt do anything, not sure what I have to do though as I have never used it before. Also have tried just including all the variables into fscanf statement, but I either get the same output, or it becomes a mess. As it is, I am extremely lost, how do I get these values into the variables they belong?!
EDIT: updated my code, I have gotten a little farther but not much. I can now print out just the last name but can not more farther from there, I cant get to the firstname string or any of the variables beyond it.
What you have there is a CSV file with quoted strings, and so I would recommend you use a CSV parser (or roll your own) rather than trying to do it all with scanf (since scanf cannot deal with quotes, e.g. commas within quoted strings). A quick Google search turns up libcsv.c which you may be able to use in your project.
With the fscanf format string "%d,%d,\"%[^\"]\",\"%[^\"]\",%[^,],%d,=\"%[^\"]\"" we can read a whole line's data. Besides, you have to define
char lastname[MAX_NAME+1];
char firstname[MAX_NAME+1];
char subjectname[MAX_SUBSEC+1];
int catalog;
char section[MAX_SUBSEC+1];
— the +1 to account for the terminating '\0' character.
I have a question for you... If you want to know how to use a diamond cutter, do you try it and see, or do you consult the manual? The problem here isn't the result of your choice, but your choice itself. Believe it or not, I have answered these questions so often that I'm tired of repeating myself. The answer is all in the manual.
Read the POSIX 2004 scanf manual — or the POSIX 2008/2013 version — and the answer this question and you'll have some idea of what you're not doing that you should be. Even fscanf code should use assert as a debugging aid to ensure the number of items read was correct.
%[^,]s It seems as though there's a mistake here. Perhaps you meant %[^,]. The %[ format specifier is a different format specifier to the %s format specifier, hence in the presumably mistaken code there are two directives: %[^,] and s. The s directive tells scanf to read an 's' and discard it.
1.There is a syntax error in
while(result != NULL){
printf(".....);
......
}
}//error
fscanf(inputf, "%s", lastname); can't read a line ,fscanf will stop when it comes across an space
fscanf reads one line at a time, and you can easily capture the contents of each line because your file is formatted pretty nicely, especially due to the comma separation (really useful if none of your separated values contain a comma).
You can pass fscanf a format like you're doing with "%d" to capture an int, "%s" to capture a string (ends at white space, be weary of this when for example trying to find a name like "Annitto Grassis, which would require 2 %s's), etc, from the currently read line of the file. You can be more advanced and use regex patterns to define the contents you want captured as chars, such as "Boatswain", a sequence comprised chars from the sets {A-Z}, {a-z}, and the {"}. You'll want to scan the file until you reach the end (signified by EOF in C) so you can do such and capture the contents of the line and appropriately assign the values to variables like so:
while( fscanf(inputf, "%d,%d,%[\"A-Za-z ],%[\"A-Za-z .]", &term, &id, lastname, firstname) != EOF) {
.... //do something with term, id, lastname, firstname - put them in a student struct
}
For more about regex, Mastering Regex by Jeff Friedl is a good book for learning about the topic.
I am new to the C programming language and trying to improve by solving problems from the Project Euler website using only C and its standard libraires. I have covered basic C fundamentals(I think), functions, pointers, and some basic file IO but now am running into some issues.
The question is about reading a text file of first names and calculating a "name score" blah blah, I know the algorithm I am going to use and have most of the program setup but just cannot figure out how to read the file correctly.
The file is in the format
"Nameone","Nametwo","billy","bobby","frank"...
I have searched and searched and tried countless things but cannot seem to read these as individual names into an array of strings(I think thats the right way to store them individually?) I have tried using sscanf/fscanf with %[^\",]. I have tried different combos of those functions and fgets, but my understanding of fgets is everytime I call it it will get a new line, and this is a text file with over 45,000 characters all on the same line.
I am unsure if I am running into problems with my misunderstanding of the scanf functions, or my misunderstanding with storing an array of strings. As far as the array of strings goes, I (think) I have realized that when I declare an array of strings it does not allocate memory for the strings themselves, something that I need to do. But I still cannot get anything to work.
Here is the code I have now to try to just read in some names I enter from the command line to test my methods.
This code works to input any string up to buffer size(100):
int main(void)
{
int i;
char input[100];
char* names[10];
printf("\nEnter up to 10 names\nEnter an empty string to terminate input: \n");
for(int i = 0; i < 10; i++)
{
int length = 0;
printf("%d: ", i);
fgets(input, 100, stdin);
length = (int)strlen(input);
input[length-1] = 0; // Delete newline character
length--;
if(length < 1)
{
break;
}
names[i] = malloc(length+1);
assert(names[i] != NULL);
strcpy(names[i], input);
}
}
However, I simply cannot make this work for reading in the formatted strings.
PLEASE advise me as to how to read it in with format. I have previously used sscanf on the input buffer and that has worked fine, but I dont feel like I can do that on a 45000+ char line? Am I correct in assuming this? Is this even an acceptable way to read strings into an array?
I apologize if this is long and/or not clear, it is very late and I am very frustrated.
Thank anyone and everyone for helping, and I am looking forward to finally becoming an active member on this site!
There are really two basic issues here:
Whether scanning string input is the proper strategy here. I would argue not because while it might work on this task you are going to run into more complicated scenarios where it too easily breaks.
How to handle a 45k string.
In reality you won't run into too many string of this size but it is nothing that a modern computer of any capacity can't easily handle. Insofar as this is for learning purposes then learn iteratively.
The easiest first approach is to fread() the entire line/file into an appropriately sized buffer and parse it yourself. You can use strtok() to break up the comma-delimited tokens and then pass the tokens to a function that strips the quotes and returns the word. Add the word to your array.
For a second pass you can do away with strtok() and just parse the string yourself by iterating over the buffer and breaking up the comma tokens yourself.
Last but not least you can write a version that reads smaller chunks of the file into a smaller buffer and parses them. This has the added complexity of handling multiple reads and managing the buffers to account for half-read tokens at the end of a buffer and so on.
In any case, break the problem into chunks and learn with each refinement.
EDIT
#define MAX_STRINGS 5000
#define MAX_NAME_LENGTH 30
char* stripQuotes(char *str, char *newstr)
{
char *temp = newstr;
while (*str)
{
if (*str != '"')
{
*temp = *str;
temp++;
}
str++;
}
return(newstr);
}
int main(int argc, char *argv[])
{
char fakeline[] = "\"Nameone\",\"Nametwo\",\"billy\",\"bobby\",\"frank\"";
char *token;
char namebuffer[MAX_NAME_LENGTH] = {'\0'};
char *name;
int index = 0;
char nameArray[MAX_STRINGS][MAX_NAME_LENGTH];
token = strtok(fakeline, ",");
if (token)
{
name = stripQuotes(token, namebuffer);
strcpy(nameArray[index++], name);
}
while (token != NULL)
{
token = strtok(NULL, ",");
if (token)
{
memset(namebuffer, '\0', sizeof(namebuffer));
name = stripQuotes(token, namebuffer);
strcpy(nameArray[index++], name);
}
}
return(0);
}
fscanf("%s", input) reads one token (a string surrounded by spaces) at a time. You can either scan the input until you encounter a specific "end-of-input" string, such as "!", or you can wait for the end-of-file signal, which is achieved by pressing "Ctrl+D" on a Unix console or by pressing "Ctrl+Z" on a Windows console.
The first option:
fscanf("%s", input);
if (input[0] == '!') {
break;
}
// Put input on the array...
The second option:
result = fscanf("%s", input);
if (result == EOF) {
break;
}
// Put input on the array...
Either way, as you read one token at a time, there are no limits on the size of the input.
Why not search the giant string for quote characters instead? Something like this:
#include <stdio.h>
#include <string.h>
int main(void)
{
char mydata[] = "\"John\",\"Smith\",\"Foo\",\"Bar\"";
char namebuffer[20];
unsigned int i, j;
int begin = 1;
unsigned int beginName, endName;
for (i = 0; i < sizeof(mydata); i++)
{
if (mydata[i] == '"')
{
if (begin)
{
beginName = i;
}
else
{
endName = i;
for (j = beginName + 1; j < endName; j++)
{
namebuffer[j-beginName-1] = mydata[j];
}
namebuffer[endName-beginName-1] = '\0';
printf("%s\n", namebuffer);
}
begin = !begin;
}
}
}
You find the first double quote, then the second, and then read out the characters in between to your name string. Then you process those characters as needed for the problem in question.
so I have been searching your website and im still very unclear on how to do this, so let me try to explain this as best I can.
I have a input file like so:
2
Joe Flacco
1 3 5 6 7 8
Tom Brady
7 9 10 15 52 53
The first number is the number of "people" in the file, and the next is their first and last name. Next is 6 ints between [0,53] that are their "lottery" numbers. Anyways, I can get my code to pull in the first number, but getting theirs names and numbers is proving hard.
The last part, is getting it to fit in the struct we have declared (which we must use, that contains variables firstName[20] lastName[20] and numbers[6]. I know I am way off on how to do this all properly, but I am posting my code so you guys can see what Im doing. I appreicate any and all help. Also, Im trying to learn how to do it, not get you to right a program for me, so any explanations are very welcome.
for(int i=0; i < numPlays;i++)
{
char firstName[20];
char lastName[20];
for(int x=0; x<3;x++)
fscanf(fr, "%c", &firstName[x]);
for(int x=0; x<6;x++)
fscanf(fr, "%c", lastName[x]);
for(int g=0; g<6; g++)
{
fscanf(fr, "%d", &Steve.numbers[g]);
}
temp[i]= Steve;
//Tester code, lets hope this works
for(int x=0; x<3;x++)
printf("The persons name is %c.\n",&firstName[x]);
//printf("The persons last name is %c.\n",temp[i].lastName);
}
Using fgets strtok and atoi will give you what you need. As for your program's structure, you probably want something like this:
typedef struct Player {
char name[20];
int numbers[6];
} Player;
#define SIZE(x) (sizeof(x)/sizeof(*(x)))
Player readplayer(){
Player p;
int x;
char * num;
//read a line with fgets;
//memcpy() to p.name;
//read another line
for(num=strtok(line, " "),x=0;x<SIZE(p.numbers);x++, num=strtok(NULL," "))
p.numbers[x] = atoi(num);
return p;
}
int main()
{
//read a line with fgets
int x, nplayers = atoi(line);
Player *players = malloc(nplayers*sizeof(Player));
for(x=0;x<nplayers;x++)
players[x] = readplayer();
}
you can use fgets() function for this purpose. it will read lines as String. after reading the numeric as string, just convert it to integer.
You could separate reading from a file and parsing the content i.e., define readline() and parse each line independently, example.
I don't work with C often so please excuse any mistakes I might be making in terms of coding style :P I'm currently getting an error that I'm a bit stumped on: when I include the line tokenCopy = malloc(sizeof(fileSize));, I get random a random exclamation about 1/4th of the way through the output of a file to std but if the line is removed/commented, the data displays as expected:
MAY +1.32 D1 1002
JUNE -1.57 D3 201
JULY -2.37 D4 478
AUGUST +5.03 D2 930
SEPTEMBER -3.00 D1 370
OCTOBER +7.69 D1 112
and the actual output I get when the line is in place:
MAY +1.32 D1 1002
JUNE -1.57 D3 2!
and the relevant code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/**
* Machine struct - three column
**/
/**
* Parses the input file, size is the size of name
**/
char parseInputFile(char *name, int size) {
FILE *fp;
if ((fp = fopen(name,"r")) == NULL) {
printf("Cannot open file %s\n", name);
return 1;
}
else {
int fileSize;
fileSize = 0;
char *fileContent;
char *processedFileContent;
//get file size
fseek(fp, 0, SEEK_END);
fileSize = ftell(fp);
fseek(fp, 0, SEEK_SET);
//allocate
fileContent = malloc(sizeof(fileSize));
processedFileContent = malloc(sizeof(fileSize));
//read
char c;
int g;
g=0;
while((c = getc(fp)) != EOF) {
fileContent[g] = c;
g++;
}
//process
char delim[6] = " ";
char *tokenCopy;
tokenCopy = malloc(sizeof(fileSize));
strcpy(tokenCopy, fileContent);
char *tokens = strtok(tokenCopy, delim);
while (tokens) {
tokens = strtok(NULL, delim);
}
puts(fileContent);
//printf("File Size: %i \n",fileSize);
//puts(tokenCopy);
return *processedFileContent;
}
}
int main(int argc, char *argv[])
{
//char *input;
if (argc == 1)
puts("You must enter a filename");
else {
int size = sizeof(argv[1]);
parseInputFile(argv[1],size);
}
return 0;
}
Could anyone offer any insight into what I'm doing wrong (or if my code is causing problems in itself)?
You put the size of the file in fileSize but then allocate only the space to store an int that is what sizeof(FileSize) will give you.
These two lines
fileContent = malloc(sizeof(fileSize));
processedFileContent = malloc(sizeof(fileSize));
should be (assuming you will treat the text you'll read as a string):
fileContent = malloc(fileSize+1);
processedFileContent = malloc(fileSize+1)
and, after having read the file content, you should put a '\0' at the end.
That said, I really don't get what you are trying to achieve by using strtok(). If you only need to separate the three components of each line, you can do it much easily while you read the file since you read it one character at the time.
If you elaborate a little bit more on what you're trying to achieve, we might have other advice.
UPDATE AFTER COMMENT BELOW
You should step back a second and reconsider your problem as I suspect you don't need to store any string at all. The first value is a month name, which can be stored as an integer, the second is a double (or float), the third seems 'Dx' with x varying from 1 to 4, again this could be an integer. It seems the name of a sensor, so I suspect it could be coded in an integer anyway as there will surely be a finite number of them. And the fourth is clearly another integer.
With a wild guess on what those fields mean, your struct would look like something like this:
struct val {
int month;
double value;
int sensor;
int var;
}
Now, you can get the values as you go one char at the time, or read an entire line and get the values from there.
Going one char at the time will not require any additional space but will result in a longer program (full of 'if' and 'while'). Reading the line will be slightly easier but will require you to handle the maximum size of a line.
A proper structuring of functions will help you a lot:
do {
if ((c = get_month(fp, &month)) != EOF)
if ((c = get_value(fp, &value)) != EOF)
if ((c = get_sensor(fp, &sensor)) != EOF)
if ((c = get_var(fp, &var)) != EOF)
measures = add_data(measures, month, value, sensor, var);
} while (c != EOF);
return measures
Where measures can be a linked list or a resizable array of your structs and assuming you'll go one char at the time.
There are quite many other details you should set before you're done, I hope this will help you find the right direction.
Your delims string is not null-terminated.
Also, the delimiters are matched character-by-character, so there is no use repeating the space six times, nor will your call to strtok match a run of six spaces. Perhaps you need something like strpbrk.