Hi All,

Any sample program in c for file integrity check..

Regards,
Nagaa

Recommended Answers

All 6 Replies

Well checking the integrity of say a JPG file would be different from say a WMV file.

A bit more details would be nice. What integrity check?

A bit more details would be nice. What integrity check?

I have one control file and more than one data file.
Control file includes the data file name and its corresponding record.
Do integrity check between control file an d raw data file.
I have to read data file name from control table and open the data file
Read the number of record in raw data file.
compare the no of record in control file should match with the number of record in data file.
If equal proceed to read the next line to do the same process
else
"Integrity check mismatch" message throw and come out of the program.


Control file look like
<xxxxx><10>
<yyyyy><20>

Raw data file look like (file name:xxxxx)
<h>
<D>
<T> 10


Raw data file look like (file name:yyyyy)
<h>
<D>
<T> 20

Both the file are same type ie flat file


Let me know.. if not understandable
Regards,
Nagaa

Do you know how to do file i/o using FILE* pointer and associated functions found in stdio.h ? If not, then read this tutorial.

To complete your homework you will have to write a program that does what you described. use two file handles -- one to read the control file one line at a time, then another to read the data file and count the number of lines in it.

Do you know how to do file i/o using FILE* pointer and associated functions found in stdio.h ? If not, then read this tutorial.

To complete your homework you will have to write a program that does what you described. use two file handles -- one to read the control file one line at a time, then another to read the data file and count the number of lines in it.

Hi,
i know the logic..
I dnt hav sample code for this..
And also i dnt know hoe to use the token to seperate the fields..
Sample code is useful for me to proceed the work..
Starting is stuck for me to go...thats y..

Ok, here is some sample code that illustrates how to do it. It is not complete so you will have to change it to fit your problem.

char ctrlline[255];
char detailline[255];
FILE* fp1;

fp1 = fopen("controlfile.txt", "r");
while( fgets(ctrline, sizeof(ctrlline), fp1) )
{
      FILE* fp2;
      char filename[255] = {0};
      char *ptr = strtok(ctrlline, " "); // split the words
      strcpy(filename,ptr); // extract the filename
      fp2 = fopen(filename, "r");
      while( fgets( detailline, sizeof(detailline), fp2) )
      {
            // do something 
      }
      fclose(fp2);
}
fclose(fp1);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.