Hi,
I am not able to open the file in read mode.Can u please tell me where i went wrong?..
I guess the value in buffer variable is not working .IF it so please kindly suggest me any solution.
Code:
int main(int argc, char* argv[])
{
int k=0;
FILE *fp;
unsigned char cd[255];
unsigned long cd1[500];
char buffer[1024];
unsigned long sa=80044;
int j=0,i=0,n=0;
DIR *dir;
struct dirent *direntry; //could be a file, or a directory
dir = opendir("C:/Documents and Settings/Administrator/Desktop/vicky");
if(!dir) {
printf("Error: directory did not open!\n");
return 1;
}
while((direntry=readdir(dir))!=NULL) {
if(++k < 100)
{
printf("%s\n",direntry->d_name);
sprintf(buffer,"%s",direntry->d_name);
fp=fopen("buffer","rb");
sa=sa-44;
sa=sa/8;
if(fp==NULL)
{
printf("file not found!");
}
else
{
for(j=0;j<(sa);j++)
{
for(i=0;i<8;i++)
{
cd[i]=fgetc(fp);//get each character from file
// printf("%c",cd[i]);
}
if(i==8)//if the i is 8 the character then do the following,just read 8 bytes and then calculate the cd1.
{
sa=sa-8;
cd1[j]=(cd[6] * 65536 + cd[5] * 256 + cd[4]);//multiply the positional weightage and calculate the cd1,which contains the 7 digits decimal value.
//if((cd1[j]> 0x7FFFFF)&&(cd1[j]<=0xFFFFFF))
//cd1[j]=cd1[j]- 0xFFFFFF;
//cd1[j]=cd1[i] * -1;
}
printf("completes first 8 bytes read:%d - %d",j,cd1[j]);//print j and cd1[j] value in console window
}
fclose(fp);//close the file
}
}
if((strcmp(direntry->d_name, "text.txt"))==0) {
printf("\nThe %s file has been found\n",direntry->d_name);
k=-99; //just a flag value to show the file was found
break;
}
}
if(k!=-99)
printf("\nThe test.txt file was not found\n");
closedir(dir);
printf("\n");
getchar();
return 0;
}