C++
Tsakiris Yannis
orb at studiofm1.cs.teiher.gr
Wed Nov 26 19:26:23 EET 1997
On Wed, 26 Nov 1997, Dimitris Demiris wrote:
> Geia sas paidia,
> Exw mia erwtisi sxetika me C. Ginetai na ftiaxw enan pinaka o
> opoios na einai metablitos stin synexeia tou programmatos? P.x. Exw ena
> arxeio me n eggrafes kai 8a i8ela na pairnei olo to arxeio kai na to
> topo8etei stin mnhmh (gia taxinomhsh). Mhn mou peite lyseis toy style:
> Anoixe ena arxeio apo ton arxi kai tetoia blepe singular. Pantws stin
> Turbo c to kanw (nomizw!) me procedure i opoia exei public metablites to
> pli8os twv eggrafwn enos arxeiou. Telos pantwn den einai dynaton na to
> kanei i basic kai i ka8e basic kai na mhn to kanei i C. Mhn me kanete na
> xasw to stoixhma.
>
struct one_line
{
char *data;
struct one_line *next;
};
#define MAX_LINE_SIZE 1024
struct one_line *load_file_in_memory(char *filename)
{
FILE *fp;
struct one_line *temp,*aLine,*prev;
char buffer[MAX_LINE_SIZE+1];
if ((fp=fopen(filename,"r")) == NULL) return NULL;
temp=NULL;
while (fgets(buffer,1024,fp))
{
int len=strlen(buffer);
aLine=(struct one_line *)malloc(sizeof(struct one_line));
aLine->data=(char *)malloc(len+1);
strcpy(aLine,buffer);
aLine->next=NULL;
if (temp == NULL)
prev->next=aLine; else
temp=aLine;
prev=aLine;
}
fclose(fp);
return temp;
}
afti i synarthsh prospa8ei na anoiksei kai na diabasei ena
arxeio kai na to fortosei sti mnimi se mia link-list. Ka8e
grammh einai ena stoixio tis lista, ka8e stoixio periexei
ta dedomena tis ka8e grammhs kai ena pointer pou dixnei stin
epomeni. i sinartisi epistrefei ena pointer pou dixnei stin
prwth grammh tou arxeiou.
an kapoia grammh ksepernaei se mikos tin MAX_LINE_SIZE tote
i grammh afth kobete se perisoteres apo mia grammes.
elpizw kati tetoio na i8eles, exw xrhsimopiisei ton parapanw
tropo gia na ftiaksw tis basikes litourgies enos epeksergasth
keimenou (na mporw efkola na sbinw-parembalw-allazw grammes).
gia na ksanadiabaseis to arxeio enas tropos einai o parakatw:
void print_file(struct one_line *origin)
{
while (origin)
{
if (origin->data) printf("%s",origin->data);
origin=origin->next;
}
}
an ksereis merika pragmata apo link-lists tote apo dw kai
pera einai poli efkolo (allazontas times stous pointers)
na taksinomiseis gia paradigma tis grammes enos arxeiou.
--Yannis Tsakiris
--
====================================================================
Gia na mathete pos na xrisimopoiite ton majordomo, stilte e-mail
sto "majordomo at argos.hol.gr" me 1 grammi sto keimeno: help
Ta archives tis listas einai sto http://www.argos.hol.gr/lists
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users
====================================================================
More information about the Linux-greek-users
mailing list