Thank you very much for example and for your time.
Problem was really in error in my code and not problem with platform (XP & HT) as I thought.
In function "fgets(line,80,fr)" I use real integrer 80 for to define to read max. characters from one line.
I think that when I use "sizeof(line)" than is posible that char-variable can be overflow out of defined memory space when it will be more than 80 characters on one line, when I define this statical variable with value 81 Bytes. I hope that it is correct.
I have another problem (but it is for new thread).
Now our code printing each line from input text-file when line contents string from COM variable:
Code:
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fr;
char file[14]="a1.txt", line[81], COM[6]="COM15";
if ( (fr = fopen(file, "r")) != NULL) {
while(fgets(line, 80, fr) != NULL ) {
if ( (strstr(line, COM)) != NULL) {
printf("%s", line);
}
}
}
}
When input text-file contents characters 0D 0A (in HEX) than WHILE-test finish. But I would like to test until the truly end of file.
Probably I need to change "while(fgets(line, 80,fr) != NULL )" but I do not how.
Maybe with EOF or feof(). Could you help me please how it is possible to make it? I am not succesful meantime.
Than I need to solve another problem:
If "(strstr(line, COM)" is true, than I need to jump -200 lines and apply another search - "(strstr(line, date)" where "date" is defined string eg. "Dec 09". This new search I need for 400 next lines and then I need to continue with first search etc. Maybe it is too complicated..
I tried to solve with "fseek(fr, (-200*80), SEEK_CUR);" where -200 is -200lines * 80 characters per one line, because I do not need to jump exactly on -200 line. But maybe exist some function for count lines, maybe it is possible to apply "fgets" but I do not know how to jump back in file. Then I tried to use :
Code:
if(strstr(line, date) != NULL) {
for(i=0;i<400;i++) {
fgets(line, 80, fr); /* read next 400 lines*/
if(strstr(line, date) != NULL) /* if line contents string "date" */
printf("%s", file); /*print filename that is suitable with conditions*/
} }
I do not know if I can want to help so much...
Maybe I must divide these problems to more threads.
Thank you for your understanding and your help.