Question: -Write a function which reads a line of any length from a file, and returns it as a string. -You are not permitted to use

-Write a function which reads a line of any length from a file, and returns it as a string.

-You are not permitted to use fgets.

-Write a test program to confirm that your function is correct.

So far I have this but cant get seem to send the file name through to the function "readin"

Thanks for your help!

#include

#include

#include

#define kFileLocation "/Read File/Read File/Data"

char* readin(FILE* file) {

int size = 100;

char* result = malloc(sizeof(char)*size);

int position = 0;

int next;

int count = 0;

while(1) {

next = fgetc(file);

if (next == EOF || next == ' ') {

result[position] = ' ';

return result;

}

if (count == 99) {

size = size + size;

result = realloc(result , size);

count = 0;

} else {

result[position++] = (char)next;

count++;

}

}

}

int main (int argc, char*argv[]) {

char* outputFile;

FILE* DataFile;

outputFile = readin(kFileLocation);

printf("%s ",outputFile);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!