Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Read part of a line with fgets and ignore rest.

$
0
0
Hi all, I have the code below where I am reading an input file, reading line by line processing it and printing it out to an output file. What I need to print out is 61 chars, but the record comes with 80 chars.

FILE *inputfile;
char fileRec[63];
inputfilename = getenv("INPUT_FILE_NAME");
inputfile = fopen(inputfilename, "r");

while(fgets(fileRec, sizeof(fileRec), inputfile) != NULL)
{
  fprintf(outfile, "%s", fileRec);
}




The records in the file are 80 chars long but I only need 61, the way I have it right, it prints the records all in one line in the output file. I need to print it in the output file line by line but only 61 chars. how can I ignore the last 19 chars?

thanks for the help.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>