Visualizzazione dei risultati da 1 a 8 su 8

Discussione: [C] Liste e File...

  1. #1

    [C] Liste e File...

    Come mai non mi copia correttamente i/il file ???

    Questa funzione prende in input la lista di file e li apre uno a uno...
    I File vanno scritti uno di seguito all'altro nel file INST_FILE_TMP...

    codice:
    #define INST_FILE_TMP   "tmpnstll.exe"
    #define DIM_BUF         11
    
    void save_file (struct fileList *p) {
       char buffer[DIM_BUF];
       FILE *fp;
       FILE *ifp;
       
       ifp = fopen (INST_FILE_TMP, "wb");
       
       while (p != NULL) {
          fp = fopen (p->inf, "rb");
          if (fp != NULL) {
             while (!feof(fp)) {
                bar_install();
                fread  (buffer, sizeof(char), 100, fp);
                fwrite (buffer, sizeof(char), 100, ifp);
                fflush (fp);
                sleep(100);
             }
             fclose (fp);
          } else {
             /* File Inesistente o Impossibile Aprirlo */
          }
          p = p->pun;
       }
       
       fclose (ifp);
    };

    L'inserimento nella lista l'ho fatto cosi' e non da problemi
    codice:
    struct fileList *request_file_list(void) {
       struct fileList *p, *paus;
       unsigned int i, n;
       
       printf ("\nQuanti File Ha il Tuo Progetto ? # ");
       scanf  ("%u", &n);
       getchar();
       
       if (n==0) {
          p = NULL;
       } else {
          p = (struct fileList *) malloc (sizeof(struct fileList *));
          
          printf ("\nFile 1 # ");
          gets (p->inf);
          
          paus = p;
          
          for (i=2; i <= n; i++) {
             paus->pun = (struct fileList *) malloc (sizeof(struct fileList *));
             paus = paus->pun;
             printf ("File %d # ", i);
             gets (paus->inf);
          }
          
          paus->pun = NULL;
       }
       return (p);
    };
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  2. #2
    kNemo, sei tenuto a rispettare il regolamento includendo nel titolo della discussiont linguggio che usi e relativa versione, per facilitare tutti nell'utilizzo del forum e nell'aiutarti.

    05.08.2005 - by alka
    Auguri all'angelo custode dei moderatori.

  3. #3
    Dho... Mi sono dimenticato...
    Scusa

    comunque il linguaggio e' C
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  4. #4

    Risolto e Velocizzato...

    Ho gia' risolto il problema...
    Grazie Comunque...

    codice:
    #define INST_FILE_TMP   "tmpnstll.exe"
    #define DIM_BUF         1024
    
    void save_file (struct fileList *p) {
       char buffer[DIM_BUF];
       FILE *fp;
       FILE *ifp;
       
       ifp = fopen (INST_FILE_TMP, "wb");
       
       while (p != NULL) {
          fp = fopen (p->inf, "rb");
          if (fp != NULL) {
             while (!feof(fp)) {
                bar_install();
                fread  (&buffer, sizeof(char), DIM_BUF, fp);
                fwrite (&buffer, sizeof(char), DIM_BUF, ifp);
                fflush (ifp);
                sleep(50);
             }
             fclose (fp);
          } else {
             /* File Inesistente o Impossibile Aprirlo */
          }
          p = p->pun;
       }
       
       fclose (ifp);
    };
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  5. #5
    Perche' aggiungendo
    fprintf (ifp, "\r\n%s\r\n", END_FILE_STR);

    mi dice che la memoria non e' Written ???

    Questo succede quando cerco di copiare due File...
    Ma Perche' ???
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  6. #6
    Mi son dimenticato di dire che uso Win XP con il
    Dev C++ 4.9.8.7
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  7. #7

    Problema nell'Apertura di un file...

    Perche' lanciando la funzione il programma mi da' questo errore ???

    L'istruzione "0x77f485c0" ha fatto riferimento alla memoria a "0x20000000". La memoria non poteva essere "written"

    codice:
    void save_file (struct fileList *p) {
       FILE *fp;
       
       fp = fopen ("file.txt", "w");   
       ...
       fclose (fp);
    };

    codice:
    /* Struttura Lista File */
    struct fileList {
       char inf [MAX_NOF_NAME];
       struct fileList *pun;
    };

    La funzione main()
    codice:
    int main(int argc, char *argv[]) {
       struct fileList *punt_lista;
    
       punt_lista = request_file_list();
       
       save_file(punt_lista);
    
       free (punt_lista);
    
       getchar();
       return 0;
    };

    Inserimento dati nella Lista
    codice:
    struct fileList *request_file_list(void) {
       struct fileList *p, *paus;
       unsigned int i, n;
       
       printf ("\nQuanti File Ha il Tuo Progetto ? # ");
       scanf  ("%u", &n);
       getchar();
       
       if (n == 0) {
          p = NULL;
       } else {
          p = (struct fileList *) malloc (sizeof(struct fileList *));
          
          printf ("\nFile 1 # ");
          gets (p->inf);
          
          paus = p;
          
          for (i=2; i <= n; i++) {
             paus->pun = (struct fileList *) malloc (sizeof(struct fileList *));
             paus = paus->pun;
             printf ("File %u # ", i);
             gets (paus->inf);
          }
          
          paus->pun = NULL;
       }
       return (p);
    };
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

  8. #8
    Help
    PoWered by:
    Gentoo 1.5.3 - Kernel 2.6.7
    Debian Sid - Kernel 2.6.7 - Bash 3.0
    Slackware current - Kernel 2.6.7

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.