Article View: es.comp.os.linux.programacion
Article #12036Re: Memoria en C
From: J.A. Gutierrez
Date: Wed, 12 Sep 2001 16:54
Date: Wed, 12 Sep 2001 16:54
70 lines
2609 bytes
2609 bytes
Reinoso G. <reinoso@probando.com> wrote:
: Hab�a pensado en lo siguiente:
: leo la cadena y cuento las comas que hay
: creo una matriz (�est�tica?)
: voy dividiendo la cadena en partes separadas por comas usando un for (no
: me convence)
: cada parte la meto en un elemento de la matriz de antes
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
[...]
long loadPictTexture(char *name)
{
char *rpath, *path, *defpath=".", *argt, p[512];
int found=0;
struct stat sbp;
[...]
if ((rpath=getenv("RMANTEXPATH"))==NULL) rpath = defpath;
if ((path = strdup(rpath))==NULL)
{
perror("LoadPictTexture");
}
argt = strtok( path, ":" );
while((argt!=NULL) && (!found))
{
/* FIXME -> limited to sizeof(p) */
sprintf(p,"%s/%s",argt,name);
if ( stat(p,&sbp)!=-1)
{
found = ((sbp.st_mode & S_IFMT)==S_IFREG);
}
argt=strtok( NULL, ":" );
}
thePict = pict_open(p,P_READ,0,0,0,NULL);
free(path);
[...]
: �luego al finalizar el programa se liberan todos los bloques
: automaticamente o tengo que liberarlos yo uno a uno?
tienes que liberar todo aquello que reserves.
No es imprescidible, pero es de muy mal estilo y muy cutre
no hacerlo.
--
PGP and other useless info at \
http://www.cps.unizar.es/~spd/ \
finger://daphne.cps.unizar.es/spd \ Timeo Danaos et dona ferentes
ftp://ivo.cps.unizar.es/pub/ \ (Virgilio)
Technical Details
Message-ID:
<9no3vn$psg$1@news.unizar.es>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!t-online.de!news-ge.switch.ch!news.rediris.es!news.unizar.es!not-for-mailReferences:
<slrn9puu43.il.reinoso@EA4BAO.PLLANO.ESP.EU>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,46d32f3a40cbfb83
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-09-12 09:34:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!t-online.de!news-ge.switch.ch!news.rediris.es!news.unizar.es!not-for-mail
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Memoria en C
Date: 12 Sep 2001 16:54:15 GMT
Organization: Rank
Lines: 70
Message-ID: <9no3vn$psg$1@news.unizar.es>
References: <slrn9puu43.il.reinoso@EA4BAO.PLLANO.ESP.EU>
NNTP-Posting-Host: daphne.cps.unizar.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.unizar.es 1000313655 26512 155.210.152.20 (12 Sep 2001 16:54:15 GMT)
X-Complaints-To: usenet@news.unizar.es
NNTP-Posting-Date: 12 Sep 2001 16:54:15 GMT
User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (IRIX/6.2 (IP22))