ciao 
scusate il titolo, ma non sapevo cosa mettere 
ho un problema con il seguente codice: le stringhe memorizzate nella lista
vengono troncate, e non riesco a capirne il motivo (ho provato a riallocare
la memoria per le stringhe, ad usare strcpy, memcpy, strncpy, ma senza
risultati degni di nota )
ogni aiuto è bene accetto 
codice:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _OneFile_OneRow OneFileOneRow;
struct _OneFile_OneRow
{
char *artist;
char *title;
char *path;
struct _OneFile_OneRow *next_file;
};
void playlist_parse(char *playlist_path);
int n_files;
int c_tot;
char *playlist_path;
OneFileOneRow *ofor;
OneFileOneRow *nxt;
int main(int argc, char ** argv)
{
extern int n_files;
extern OneFileOneRow *ofor;
int i;
playlist_parse(argv[1]);
printf("\n\n%s\n%s\n%s\n\n",
"#################################",
"# N° ARTIST TITLE PATH #",
"#################################");
/* we read the list */
for ( i = 0; i < n_files; ++i)
{
if (i < 10)
putchar(' ');
/*
* as you can see, the strings stored in the various
* artist, title and path have been truncated
*/
printf("[%d] %s %s %s\n", i,
ofor->artist , ofor->title ,ofor->path);
ofor = ofor->next_file;
}
return 0;
}
void playlist_parse(char *path_to_list)
{
/*
* The playlist format is something like:
*
* ARTIST*TITLE@PATH<newline>
* ARTIST*TITLE2@PATH2<newline>
* etc...
*
* (just here, not in the real program)
*/
FILE *list;
char *buffer;
char c;
int n_c = 0;
playlist_path = path_to_list;
list = fopen(playlist_path, "r");
/*
* we will not test if mem has been properly allocated
* just because this is not the full program
*/
ofor = calloc(1, sizeof (OneFileOneRow));
buffer = calloc(1, sizeof (char *));
nxt = ofor;
for (c_tot = 0; (c = getc(list)) != EOF ; ++c_tot)
{
/*
* the various printf() functions show the string stored
* in buffer is correct
*/
if (c == '\n')
{
*(buffer + n_c) = '\0';
if (n_files < 10)
putchar(' ');
printf("[%d]nxt.PATH %s\n", n_files, buffer);
nxt->path = buffer;
buffer = calloc(1, sizeof (char *));
nxt->next_file = calloc(1, sizeof (OneFileOneRow));
nxt = nxt->next_file;
n_c = 0;
++n_files;
}
else if (c == '*')
{
*(buffer + n_c) = '\0';
if (n_files < 10)
putchar(' ');
printf("[%d]nxt.ARTIST %s\n", n_files, buffer);
nxt->artist = buffer;
buffer = calloc(1, sizeof (char *));
n_c = 0;
}
else if (c == '@')
{
*(buffer + n_c) = '\0';
if (n_files < 10)
putchar(' ');
printf("[%d]nxt.TITLE %s\n", n_files, buffer);
nxt->title = buffer;
buffer = calloc(1, sizeof (char *));
n_c = 0;
}
else
{
*(buffer + n_c) = c;
++n_c;
}
}
nxt = NULL;
free(buffer);
fclose(list);
return;
}
Grazie in anticipo a tutti