how to do...

This is a discussion on how to do... within the C Programming forums, part of the General Programming Boards category; Hello I have a problem with files calculating.... I do the program but then it do chdir("..") and the you ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    Question how to do...

    Hello

    I have a problem with files calculating....

    I do the program but then it do chdir("..") and the you do system("dir.......") it start reading directoriesfrom the first but i want that it start reading in line which number belongs with how many time was doing cycle.

    there is my program:
    Code:
    #include <stdio.h>
    #include <dir.h>
    #include <direct.h>
    #include <dirent.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <io.h>
    #include <process.h>
    #include <dos.h>
    
     char kata[8];
     struct ffblk ffblk;
     int taip;
     long kiek=0;
    
     int chdir (const char *kata);
     int kiekis (char *kata);
    
    
      int kiekis(char *kata) {
    
           FILE *f;
    
           if (chdir (kata) == 0){
    	   taip = findfirst("*.*",&ffblk,0);
    	   while (!taip)
    		 {kiek=kiek+1;
    		  taip = findnext(&ffblk);}}
    	       FILE_SEEK
      system("dir/ad/b>temp.txt");
    
      f = fopen ("temp.txt", "r");
    
      while (fscanf(f,"%s",kata)!=EOF) {
           chdir (kata);
           if (chdir (kata) == 0){
    	   taip = findfirst("*.*",&ffblk,0);
    	     while (!taip)
    		   {kiek=kiek+1;
    		    taip = findnext(&ffblk);}}
    
    	system ("dir/ad/b > temp.txt");
           if (fscanf(f,"%s",kata)==EOF) {
    	  chdir ("..");system ("dir/ad/b > temp.txt");}
    	  else kiekis (kata);}
    
    
     fclose (f);
     return (0);}
    
    
     int main() {
     int d;
     long kiek3=0,kiek2=0;
     FILE *ff;
     clrscr ();
    
     printf ("\nSet the disk where you want to calculate files\n");
     scanf ("%d",&d);
     _chdrive (d);
     chdir ("\\");
    
     if (_chdrive(d) == 0){
       taip = findfirst("*.*",&ffblk,0);
       while (!taip)
       {  kiek2=kiek2+1;
          taip = findnext(&ffblk);}}
    
     system ("dir/ad/b > temp2.txt");
     ff = fopen ("temp2.txt","r");
    
     while (fscanf (ff,"%s",kata)!=EOF) {
           kiekis (kata);
           kiek3= kiek+kiek3;}
           if (fscanf (ff,"%s",kata)==EOF){
       kiek3 = kiek3 + kiek2;
       printf("\n there are files %d",kiek3);}
    
     getch();
     return (0);}

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Maybe some of these will inspire you
    http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    Rather than leaving a temp.txt scattered in every single directory on your disk.

    Given the number of ancient header files you've included, perhaps a more up to date compiler is in order as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21