Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created July 22, 2015 03:31
Show Gist options
  • Select an option

  • Save d30jeff/d58e651f00ac84d67486 to your computer and use it in GitHub Desktop.

Select an option

Save d30jeff/d58e651f00ac84d67486 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
char* getConfig(int lineNumber)
{
// const char fileName[150] = filePath;
FILE *file;
file = fopen("config.txt", "r");
int count = 0;
if (file != NULL)
{
char singleLine[100];
while (fgets(singleLine, sizeof singleLine, file) != NULL)
{
if (count == lineNumber - 1)
{
return ("%s", singleLine);
}
else
{
count++;
}
}
}
fclose(file);
}
int main(void)
{
const char* myString = getConfig(4);
printf("%s", myString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment