06-23-2011 06:31 PM
Hi to all,
I created a struct profile defined as follows:
typedef struct profile {
char name [30];
float power;
double frequency;
struct profile * next;
}
I can write the structures in a file, but I should do so that when you try to insert a struct, you control the field name and only if there is no other struct with that name,it is inserted in the file .
Please help me !!!
Solved! Go to Solution.
06-24-2011 02:41 AM
I tried this way
#include <ansi_c.h>
#include <cvirte.h>
char nuovo[50];
int cmp;
FILE *fp;
struct profilo
{
char nome[50];
float potenza;
double frequenza;
}p;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
fp = fopen ("c:\\Program Files (x86)\\National Instruments\\CVI81\\ESERCITAZIONI\\scrittura file 2\\profili.txt", "ab+");
printf("Insert name: \n");
scanf("%s",nuovo);
do
{
fseek(fp,sizeof(struct profilo),SEEK_SET);
fread(&p,sizeof(struct profilo),1,fp);
//printf("nome: %s\n",nuovo);
//printf("p.nome: %s\n",p.nome);
p.nome==nuovo;
printf("p.nome dopo: %s\n",p.nome);
cmp=strcmp(p.nome,nuovo);
if(cmp=0)
{
printf("Already exists\n");
fclose(fp);
}
else
{
p.nome==nuovo;
scanf("%f%lf",&p.potenza,&p.frequenza);
}
}while(!feof(fp));
fclose(fp);
return 0;
}
but don't work .
06-24-2011 09:03 AM
I solved !!!