int restore(struct x* *pirm,struct x* *pask) //sumeta viska is Disko DB i RAM DB
{
char buff[BUFFLEN];
struct x *tmp;
FILE *f;
f = fopen("SDB.txt","r");
DelAll(pirm,pask);
while(fscanf(f,"%[^\n]%*c",buff) != EOF)
{
if(strncmp(buff,"------",6) == 0)
{
if(*pirm == NULL)
{
tmp = malloc(sizeof(struct x));
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->login,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->passwd,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->vardas,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->pavarde,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->automarke,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->skundas,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->pronuomone,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->kaina,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->data,buff);
tmp->kaire = NULL;
tmp->desine = NULL;
*pirm = tmp;
*pask = tmp;
}
else
{
tmp = malloc(sizeof(struct x));
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->login,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->passwd,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->vardas,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->pavarde,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->automarke,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->skundas,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->pronuomone,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->kaina,buff);
fscanf(f,"%[^\n]%*c",buff);
strcpy(tmp->data,buff);
tmp->kaire = *pask;
tmp->desine = NULL;
(*pask)->desine = tmp;
*pask = tmp;
}
}
}
fclose(f);
}
Ok this is a part from my C programm, little bit messy but don't mind any line that start with *, these are pointers...
fscanf(f,"%[^\n]%*c",buff) - copies a line from file "f" file , "%[^\n]%*c" - indicates to read a line until a new line character, buff is where the read line is put, this char array is of 1024 size :)
The pirm and pask, are first and last, these are pointer to a custom list :)