D
Dadio
Hi!
I have to take some strings from a file and put them in a record...
The various strings in the file are written on this way:
string1|string2|string3|string4|string5|
This is the program that i have just made...what's wrong?
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct table
{
char *protocol;
char *object;
char *destinat;
char *fax;
char *note;
};
FILE *fd; //file dove risiedono i dati
void main()
{
clrscr();
int x=0;
table *grid;
fd=fopen("c:\\registro.txt","r"); //file with 5 strings to
put in the record
for (x=0;x<5;x++) //for example 5
fscanf(fd,"%s|%s|%s|%s|%s|",grid[x].protocol,grid[x].object,grid[x].destinat,grid[x].fax,grid[x].note);
//this was just to verify that the strings were stored in the record
for (x=0;x<5;x++)
{
printf("%s %s %s %s
%s",grid[x].protocol,grid[x].object,grid[x].destinat,grid[x].fax,grid[x].note);
getch();
}
fclose(fd);
}
I've tried another method too...
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct table
{
char *protocol;
char *object;
char *destinat;
char *fax;
char *note;
};
FILE *fd;
void main()
{
clrscr();
int x=0;
table *grid;
char a=' ';
int b=0;
fd=fopen("c:\\registro.txt","r");
for (x=0;x<5;x++) //for example 5
{
while(a!='|')
{
a=fgetc(fd);
grid[x].protocol=a;
b++;
}
b=0;a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].object=a;
b++;
}
b=0;a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].destinat=a;
b++;
}
b=0; a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].fax=a;
b++;
}
b=0; a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].note=a;
b++;
}
} */
fclose(fd);
}
I'd like in particoular a solution for the 1st method...
I'm sorry if i'm writing stupid things but i'm still studying C at the
high school...
Thank u
PS:sorry for my english too
I have to take some strings from a file and put them in a record...
The various strings in the file are written on this way:
string1|string2|string3|string4|string5|
This is the program that i have just made...what's wrong?
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct table
{
char *protocol;
char *object;
char *destinat;
char *fax;
char *note;
};
FILE *fd; //file dove risiedono i dati
void main()
{
clrscr();
int x=0;
table *grid;
fd=fopen("c:\\registro.txt","r"); //file with 5 strings to
put in the record
for (x=0;x<5;x++) //for example 5
fscanf(fd,"%s|%s|%s|%s|%s|",grid[x].protocol,grid[x].object,grid[x].destinat,grid[x].fax,grid[x].note);
//this was just to verify that the strings were stored in the record
for (x=0;x<5;x++)
{
printf("%s %s %s %s
%s",grid[x].protocol,grid[x].object,grid[x].destinat,grid[x].fax,grid[x].note);
getch();
}
fclose(fd);
}
I've tried another method too...
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct table
{
char *protocol;
char *object;
char *destinat;
char *fax;
char *note;
};
FILE *fd;
void main()
{
clrscr();
int x=0;
table *grid;
char a=' ';
int b=0;
fd=fopen("c:\\registro.txt","r");
for (x=0;x<5;x++) //for example 5
{
while(a!='|')
{
a=fgetc(fd);
grid[x].protocol=a;
b++;
}
b=0;a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].object=a;
b++;
}
b=0;a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].destinat=a;
b++;
}
b=0; a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].fax=a;
b++;
}
b=0; a=' ';
while(a!='|')
{
a=fgetc(fd);
grid[x].note=a;
b++;
}
} */
fclose(fd);
}
I'd like in particoular a solution for the 1st method...
I'm sorry if i'm writing stupid things but i'm still studying C at the
high school...
Thank u
PS:sorry for my english too