B
Benedicte
Hi,
I'm getting some problems when using fscanf to read a file.
This is a piece of the program code:
main ()
{
/*** Variable declaration ***/
FILE *vpfile; /*** Data file ***/
struct line
{
char old_al[10];
char new_al[10];
char vp[5];
char new_dl[17];
};
struct line l[1000]={0};
int i=0;
int nl=0; /*** number of lines read ***/
int res=0;
/*** Executable statements ***/
/*** Open VpMove.txt file ***/
vpfile=fopen("/export/home/granite/CAPI/prog/bin/VpMove.txt","r");
if(vpfile==NULL)
{
printf("The file VpMove.txt could not be opened\n");
return;
}
/*** Read datafile ***/
while(fscanf(vpfile,"%s",l.old_al)!=EOF)
{
fscanf(vpfile,"%s",l.new_al);
fscanf(vpfile,"%s",l.vp);
fscanf(vpfile,"%s",l.new_dl);
i++;
}
nl=i-1; /*** undo i++ ***/
for(i=0;i<=nl;i++)
{
printf("Line %d %s\t %s\t %s\t
%s\n",i,l.old_al,l.new_al,l.vp,l.new_dl);
}
fclose(vpfile);
}
The VpMove.txt file looks like this:
003360073 003362061 240 AP-B_LIE_PP01-523
003360073 003351154 244 AP-B_LIE_PP01-10
003360073 003351154 243 AP-B_LIE_PP01
The output is the following:
Line 0 003360073 003362061 240 AP-B_LIE_PP01-523003360073
Line 1 003360073 003351154 244 AP-B_LIE_PP01-10
Line 2 003360073 003351154 243 AP-B_LIE_PP01
The problem is that when the word ends with a minus sign followed by 3
digits (see first line) he takes directly the following word: so
instead of AP-B_LIE_PP01-523 I receive AP-B_LIE_PP01-523003360073.
Can someone help me on this one?????
I'm getting some problems when using fscanf to read a file.
This is a piece of the program code:
main ()
{
/*** Variable declaration ***/
FILE *vpfile; /*** Data file ***/
struct line
{
char old_al[10];
char new_al[10];
char vp[5];
char new_dl[17];
};
struct line l[1000]={0};
int i=0;
int nl=0; /*** number of lines read ***/
int res=0;
/*** Executable statements ***/
/*** Open VpMove.txt file ***/
vpfile=fopen("/export/home/granite/CAPI/prog/bin/VpMove.txt","r");
if(vpfile==NULL)
{
printf("The file VpMove.txt could not be opened\n");
return;
}
/*** Read datafile ***/
while(fscanf(vpfile,"%s",l.old_al)!=EOF)
{
fscanf(vpfile,"%s",l.new_al);
fscanf(vpfile,"%s",l.vp);
fscanf(vpfile,"%s",l.new_dl);
i++;
}
nl=i-1; /*** undo i++ ***/
for(i=0;i<=nl;i++)
{
printf("Line %d %s\t %s\t %s\t
%s\n",i,l.old_al,l.new_al,l.vp,l.new_dl);
}
fclose(vpfile);
}
The VpMove.txt file looks like this:
003360073 003362061 240 AP-B_LIE_PP01-523
003360073 003351154 244 AP-B_LIE_PP01-10
003360073 003351154 243 AP-B_LIE_PP01
The output is the following:
Line 0 003360073 003362061 240 AP-B_LIE_PP01-523003360073
Line 1 003360073 003351154 244 AP-B_LIE_PP01-10
Line 2 003360073 003351154 243 AP-B_LIE_PP01
The problem is that when the word ends with a minus sign followed by 3
digits (see first line) he takes directly the following word: so
instead of AP-B_LIE_PP01-523 I receive AP-B_LIE_PP01-523003360073.
Can someone help me on this one?????