Skip to content

Instantly share code, notes, and snippets.

@d30jeff
Created July 21, 2015 03:56
Show Gist options
  • Select an option

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

Select an option

Save d30jeff/792c897ab61985b8cfbf to your computer and use it in GitHub Desktop.
Read .txt file in C
int read_config(char filePath, int lineNumber, char *lineValue)
{
const char fileName[150] = filePath;
FILE *file;
file = fopen(fileName, "r");
int count = 0;
if (file != NULL)
{
char singleLine[200];
while (fgets(singleLine, sizeof singleLine, file) != NULL)
{
if (count == lineNumber)
{
printf(singleLine);
}
else
{
count++;
}
}
}
fclose(file);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment