thanks for all the suggestions. however, i have not really grasped the concept of pointers, and since my text files (well, some are binary) are rather straightforward and i am only extracting a few parameters, i think i will avoid pointers for the time being. so, i have written the following to pick out the lines that contain the desired parameter:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
FILE *infile;
FILE *outfile;
infile = fopen("/media/Data/some_text_file", "rb");
outfile = fopen("/media/Data/output", "w");
long int length = 1000; //an arbitrary maximum length for each line
char str[length];
char str1[] = "desired_parameter";
int i = 1;
while (!feof(infile)) {
fgets(str, 1000, infile);
if(strstr(str, str1) == NULL) {}
else {
fprintf(outfile, "string%i found: %s\n", i, str);
i++;
}
}
if(i==1) fprintf(outfile, "your search for %s is not found anywhere in the document\n", str1);
fclose(infile);
fclose(outfile);
return 0;
}
this works just fine, and returns what i want.
however, the next part i want to do is to break down each retrieved line into separate components and retrieve just 1. each line is basically made up of 1 to 2 words and 2-3 numbers (floating point), ie each line has about 3-5 components, each separated by a space/tab. how should i go about doing that?