Discussion:
¿Y esto?
(demasiado antiguo para responder)
Pepe Guay
2003-07-02 21:30:14 UTC
Permalink
Me revienta un programa que estoy haciendo por culpa de una función muy
sencillita. Es esta:

int tam_archivo(char* nom)
{
FILE *f;
int tam;

f = open(nom,'r');
if (f == NULL) {
fprintf(stderr,"El fichero %s no existe\n",nom);
}
tam = filelength(fileno(f));
fclose(f);
return tam;
}

warning: assignment makes pointer from integer without a cast
J. L.
2003-07-02 21:39:11 UTC
Permalink
Post by Pepe Guay
Me revienta un programa que estoy haciendo por culpa de una
int tam_archivo(char* nom)
{
FILE *f;
int tam;
f = open(nom,'r');
^^^^^^^^^^^^^^^^^^
Post by Pepe Guay
if (f == NULL) {
fprintf(stderr,"El fichero %s no existe\n",nom);
}
tam = filelength(fileno(f));
fclose(f);
return tam;
}
warning: assignment makes pointer from integer without a cast
Es porque open() (no estandard, aunque si POSIX) regresa un
entero, y -1 en caso de fallo. Dos opciones:

1) utiliza fopen().
2) cambia tu codigo a:

int tam_archivo(char* nom)
{
int f;
int tam;

f = open(nom,'r');
if (f == -1) {
fprintf(stderr,"El fichero %s no existe\n",nom);
}
tam = filelength(f);
close(f);
return tam;
}


Saludos
--
José L. Sánchez Garrido
Luis Angel Fdez. Fdez.
2003-07-03 08:42:42 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A las 21:39 del miércoles 02 de julio,
J. L. <***@inbox.lv>
hablando de Re: ¿Y esto?
en es.comp.lenguajes.c dijo...
Post by Pepe Guay
int tam_archivo(char* nom)
{
int f;
int tam;
f = open(nom,'r');
if (f == -1) {
fprintf(stderr,"El fichero %s no existe\n",nom);
}
tam = filelength(f);
close(f);
De todas formas, si el fichero no existe esas dos líneas
seguirá ejecutándolas ¿no debería evitarse?
Post by Pepe Guay
return tam;
}
Ta llueu.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/A+yC/gMpgFpBRbwRAjk3AKCeO92A/L3rE96E++eNwodcet2IFQCcCTz1
SWRnh0+qEcyMZIFBhDpUIsU=
=rWBS
-----END PGP SIGNATURE-----
--
Slackware 9.0.0 AMD Athlon(tm) Processor 598.866MHz
Kernel 2.4.21-grsec Linux User #99754
up 4 days, 18:29, 6 users, load average: 0.07, 0.04, 0.02
http://muxin.yi.org/~koxo/ http://muxin.no-ip.org/~koxo/
Julián Albo
2003-07-03 08:50:47 UTC
Permalink
Post by Pepe Guay
f = open(nom,'r');
f= fopen (nom, "r");

Salu2
Loading...