Discussione: [C]Files
View Single Post
Old 23-02-2005, 19:02   #4
anx721
Senior Member
 
L'Avatar di anx721
 
Iscritto dal: Oct 2002
Cittā: Roma
Messaggi: 1502
programma per leggere un intero file di testo in una stinga:

Codice PHP:
/* fread example: read a complete file */
#include <stdio.h>
#include <stdlib.h>

int main () {
  
FILE pFile;
  
long lSize;
  
char buffer;

  
pFile fopen "myfile.txt" "rb" );
  if (
pFile==NULL) exit (1);

  
// obtain file size.
  
fseek (pFile SEEK_END);
  
lSize ftell (pFile);
  
rewind (pFile);

  
// allocate memory to contain the whole file.
  
buffer = (char*) malloc (lSize);
  if (
buffer == NULL) exit (2);

  
// copy the file into the buffer.
  
fread (buffer,1,lSize,pFile);


  
// terminate
  
fclose (pFile);
  
free (buffer);
  return 
0;

http://www.cplusplus.com/ref/

per documentarti sulla libreria del c
__________________
Sun Certified Java Programmer
EUCIP Core Level Certified

European Certification of Informatics Professionals
anx721 č offline   Rispondi citando il messaggio o parte di esso