So, you need to get your input from a string(char*) rather that an input stream(FILE*).
I think, in your case, you can just replace:
Code:
// input is a FILE*
if( fgets(line,MAXLINE,input) == NULL )
with:
Code:
// input is a char*
strncpy(line, input, MAXLINE);
line[MAXLINE - 1] = '\0';
This may get more than one line, but I don't think this matters in your code.
If you do need only the one line you can use this function:
Code:
char* GetLineFromString(char* out, int max_length, const char* in)
{
char* pnew_line = strchr(in, '\n');
int char_count;
if (pnew_line)
{
char_count = min(max_length - 1, (pnew_line - in) + 1);
}
else
{
char_count = max_length - 1;
}
strncpy(out, in, char_count);
out[char_count] = '\0';
return (strlen(out) ? out : NULL);
}
GetLineFromString(line, MAXLINE, input);
or maybe someone will post a much nicer way to use sscanf() to do this.