Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Dreame Aqua10 Ultra Roller, la pulizia di casa con un rullo
Dreame Aqua10 Ultra Roller, la pulizia di casa con un rullo
Il più recente robot per la pulizia domestica di Dreame, modello Aqua10 Ultra Roller, abbina un potente motore di aspirazione della polvere a un sofisticato sistema di lavaggio con rullo integrato. Il tutto governato dalla logica di intelligenza artificiale, per i migliori risultati
Recensione Realme 15 Pro Game Of Thrones: un vero cimelio tech per pochi eletti
Recensione Realme 15 Pro Game Of Thrones: un vero cimelio tech per pochi eletti
Siamo volati fino a Belfast, capitale dell'Irlanda Del Nord, per scoprire il nuovo Realme 15 Pro 5G Game Of Thrones Limited Edition. Una partnership coi fiocchi, quella tra Realme e HBO, un esercizio di stile davvero ben riuscito. Ma vi raccontiamo tutto nel nostro articolo
GIGABYTE GAMING A16, Raptor Lake e RTX 5060 Laptop insieme per giocare al giusto prezzo
GIGABYTE GAMING A16, Raptor Lake e RTX 5060 Laptop insieme per giocare al giusto prezzo
Il Gigabyte Gaming A16 offre un buon equilibrio tra prestazioni e prezzo: con Core i7-13620H e RTX 5060 Laptop garantisce gaming fluido in Full HD/1440p e supporto DLSS 4. Display 165 Hz reattivo, buona autonomia e raffreddamento efficace; peccano però le USB e la qualità cromatica del pannello. Prezzo: circa 1200€.
Tutti gli articoli Tutte le news

Vai al Forum
Discussione Chiusa
 
Strumenti
Old 12-04-2008, 17:28   #1
_=<ne0h>=_
Junior Member
 
Iscritto dal: Apr 2008
Messaggi: 9
Problema con visualizzazione file di testo!

Scusate,
ho questa funzione per visualizzare un file di testo:
Codice:
#define CR 13            /* Decimal code of Carriage Return char */
#define LF 10            /* Decimal code of Line Feed char */
#define EOF_MARKER 26    /* Decimal code of DOS end-of-file marker */
#define MAX_REC_LEN 1024 /* Maximum size of input buffer */
#define MAX_NUM_LINE 32
#define MAX_LINE_LENGTH 30

int T_fgetc(FILE *input, char *output){
  int  iReturn   = 1;  /* Return value (Innocent until proved guilty) */
  int  iThisChar;      /* Current character */
  int  isNewline = 0;  /* Boolean indicating we've read a CR or LF */
  long lIndex    = 0L; /* Index into read buffer */

  while (1) /* Will exit on error, end of line, or end of file */
  {
    iThisChar = fgetc(input);     /* Read the next character */

    if (ferror(input))            /* Error reading */
    {
      iReturn = -1;           /* Convert to negative number */
      break;
    }

    if (iThisChar == EOF)         /* End of file reached */
    {
 
      if (lIndex > 0)
        ungetc(iThisChar, input);

      else           /* Nothing read but EOF; we're done with the file */
        iReturn = 0;

      break;
    }

    if (!isNewline) /* Haven't read a CR or LF yet */
    {
      if (iThisChar == CR || iThisChar == LF) /* This char IS a CR or LF */
        isNewline = 1;                        /* Set flag */
    }

    else            /* We've already read one or more CRs or LFs */
    {
      if (iThisChar != CR && iThisChar != LF) /* This char is NOT a CR or LF */
      {
        ungetc(iThisChar, input);             /* Put char back in stream */
        break;                                /* Done reading this line */
      }
    }

    output[lIndex++] = iThisChar;             /* Put char in read buffer */

  } /* end while (1) */

  output[lIndex] = '\0';                      /* Terminate the read buffer */
  return iReturn;

} /* end T_fgetc() */

void PrintLine(char *szReadLine,  long lLineCount, long lLineLen, long lThisFilePos, long *lLastFilePos, int  isFilePosErr){
  char *cPtr;
  cPtr = szReadLine;
  for (cPtr = szReadLine; cPtr <= szReadLine + lLineLen; cPtr++)
  {
            switch (*cPtr)
            {
             case 0:          /* Null terminator */
                  break;
             case CR:                /* Carriage return */
                  break;
             case LF:                /* Line feed */
                  printf("\n");
                  break;
             default:                /* A 'real' character */
                  printf("%c", *cPtr);
                  break;
             }
  }
  printf("\n");
  return;

}

int Reader(char* filen, int linestart)
{
  int (*GetLine[1])(FILE*, char*) = { T_fgetc };
  char tmode[5];
  int   iReadMode=0;             /* Index into *GetLine[] array */
  int   iReadReturn;             /* Result of read function */
  int   isFilePosErr;            /* Boolean indicating file offset error */
  long  lFileLen;                /* Length of file */
  long  lLastFilePos;            /* Byte offset of end of previous line */
  long  lLineCount;              /* Line count accumulator */
  long  lLineLen;                /* Length of current line */
  long  lThisFilePos;            /* Byte offset of start of current line */
  char  szReadLine[MAX_REC_LEN];
  FILE *inputFilePtr;            /* Pointer to input file */

  strcpy(tmode, "t");

  if (strcmp(tmode, "t") == 0)
    inputFilePtr = fopen(filen, "r");  /* Open in TEXT mode */

  else if (strcmp(tmode, "b") == 0)
    inputFilePtr = fopen(filen, "rb"); /* Open in BINARY mode */

  if (inputFilePtr == NULL )             /* Could not open file */
  {
    printf("Error opening %s\n", filen);
    return 1;
  }
  
  fseek(inputFilePtr, 0L, SEEK_END);     /* Position to end of file */
  lFileLen = ftell(inputFilePtr);        /* Get file length */
  rewind(inputFilePtr);                  /* Back to start of file */
  
  lLineCount   =  0L; /* No lines read yet */
  lLastFilePos = -1L; /* So first line doesn't show an offset error */
  
  cls();
  while (1)
  {
    isFilePosErr = 0;
    lThisFilePos = ftell(inputFilePtr);
    if (lThisFilePos != lLastFilePos + 1){
                     isFilePosErr = 1;
                     }
      szReadLine[0] = '\0';

    /* Read the next line with the appropriate read function */
    iReadReturn = (*GetLine[iReadMode])(inputFilePtr, szReadLine);

    if (iReadReturn < 0)
    {
      printf("Error reading: %s\n", filen);
      break;
    }
    lLineLen = strlen(szReadLine); /* Get length of line */
    if (lLineLen)                  /* Got some data */
    {
      ++lLineCount;                /* Increment line counter */
    }
    
    if(lLineCount>=linestart && lLineCount<(linestart+MAX_NUM_LINE)){
                 PrintLine(szReadLine, lLineCount, lLineLen, lThisFilePos, &lLastFilePos, isFilePosErr);
    }
    if (iReadReturn == 0)          /* End of file reached */
       break;
  }
  fclose(inputFilePtr); /* Close the file */
  return 0;
}
Il problema è che devo poter scorrere il testo e non posso usare delle API, con la funzione Reader dovrei passare il nome del file e la linea di partenza per la visualizzazione sullo schermo, ed essa aumenta e diminuisce quando premo rispettivamente giu e su!, solo che quando avvio questa funzione mi viene fuori un bel casino, dato che se la stringa è più lunga della finestra me la manda a capo e la conta come un'altra linea!
Qualcuno può darmi una aiuto?
_=<ne0h>=_ è offline  
Old 14-04-2008, 23:51   #2
cionci
Senior Member
 
L'Avatar di cionci
 
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
Thread chiuso
|
V
cionci è offline  
 Discussione Chiusa


Dreame Aqua10 Ultra Roller, la pulizia di casa con un rullo Dreame Aqua10 Ultra Roller, la pulizia di casa c...
Recensione Realme 15 Pro Game Of Thrones: un vero cimelio tech per pochi eletti Recensione Realme 15 Pro Game Of Thrones: un ver...
GIGABYTE GAMING A16, Raptor Lake e RTX 5060 Laptop insieme per giocare al giusto prezzo GIGABYTE GAMING A16, Raptor Lake e RTX 5060 Lapt...
iPhone 17 Pro: più di uno smartphone. È uno studio di produzione in formato tascabile iPhone 17 Pro: più di uno smartphone. &Eg...
Intel Panther Lake: i processori per i notebook del 2026 Intel Panther Lake: i processori per i notebook ...
Sempre più vicino il lancio (e il...
L'incredibile ottimizzazione di Battlefi...
La NASA aprirà il contratto per i...
PS5 Pro CFI-7121: ecco tutte le differen...
SpaceX ha raggiunto il traguardo dei 10....
ROG Xbox Ally e Ally X sono care, ma il ...
Intesa Sanpaolo: stop all'app Mobile su ...
Gli USA costruiscono chip AI… ma non pos...
Grazie a Ericsson, l'italia è in ...
CMF by Nothing Buds 2a: ANC da 42 dB e o...
Il futuro di Porsche è ibrido: il...
Apple lancia i nuovi MacBook Pro e iPad ...
Free software e biologia: intervista al ...
Dongfeng Box bocciata da Euro NCAP: solo...
Parigi abbandona ufficialmente Eurodrone...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 02:03.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Served by www3v