Salve a tutti,
ho un problema con questo programma, non riesco a passare il valore corretto, ma prende il puntatore della casella. Posto il codice con insieme la prova
codice:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct mmbox_mail
{
char *sender,*recipient; // mittente e destinatario
char *obj,*date; //oggetto e data messaggio
char flag; // letto o non letto per la cancellazione
size_t size; //dimensioni in bytes del corpo del messaggio
};
int main()
{ //x la data
time_t rawtime;
time ( &rawtime );
// x scrive un messaggio
char *path="/home/kyo/provaMSG.txt";
struct mmbox_mail writeMail;
writeMail.sender="an;toni;o";
writeMail.recipient=";fran;ces;; co";
writeMail.obj="E;mail;; la;vo;;rativa";
writeMail.date=ctime (&rawtime);
char *msg="Ciao francesco + un sacco di tempo che nn ti mandavo un email, bellla";
FILE *f=fopen(path, "a+");
fprintf(f,"\n%s;;;%s;;;%s;;;%s;;;\n\n",writeMail.sender,writeMail.recipient,writeMail.obj,writeMail.date);//levo il msg x prova "%s;;;",msg
writeMail.size=strlen(msg);//strlen(date) occupa 25
printf("%lu\n",(unsigned long)writeMail.size);
// x leggere tutti i messaggi di un file
rewind(f);
int i=0,k=0,j=0,x=0;
char app,app2=';';
char str[200];
struct mmbox_mail AwriteMail[100];
printf("big while\n");
//while(!feof(f))
//{
//AwriteMail=malloc(k+1);
i=0;
while(i!=3)
{
app=fgetc(f);
if(app==app2)
i++;
else
{
if(i!=0)
{
for(j=0;j<i;j++)
{
str[x]=(char)app2;
x++;
}
i=0;
}
str[x]=(char)app;
x++;
}
}
str[x]='\0';
puts(str);
AwriteMail[k].sender=str; // PROBLEMA
x=0;
i=0;
while(i!=3)
{
app=fgetc(f);
if(app==app2)
i++;
else
{
if(i!=0)
{
for(j=0;j<i;j++)
{
str[x]=(char)app2;
x++;
}
i=0;
}
str[x]=(char)app;
x++;
}
}
str[x]='\0';
puts(str);
AwriteMail[k].recipient=str; // PROBLEMA
x=0;
i=0;
while(i!=3)
{
app=fgetc(f);
if(app==app2)
i++;
else
{
if(i!=0)
{
for(j=0;j<i;j++)
{
str[x]=(char)app2;
x++;
}
i=0;
}
str[x]=(char)app;
x++;
}
}
str[x]='\0';
puts(str);
AwriteMail[k].obj=str; // PROBLEMA
x=0;
i=0;
while(i!=3)
{
app=fgetc(f);
if(app==app2)
i++;
else
{
if(i!=0)
{
for(j=0;j<i;j++)
{
str[x]=(char)app2;
x++;
}
i=0;
}
str[x]=(char)app;
x++;
}
}
str[x]='\0';
puts(str);
AwriteMail[k].date=str; // PROBLEMA
x=0;
i=0;
// }
close(f);;
puts(str);
str[0]='a';
str[1]='\0';
puts(AwriteMail[k].obj);
printf("\n%s %s %s %s \n\n",AwriteMail[k].sender,AwriteMail[k].recipient,AwriteMail[k].obj,AwriteMail[k].date);
return 0;
}
Ringrazio già tutti quelli che cercheranno di aiutarmi