-
why i get this errors..
1>c:\documents and settings \my documents\visual studio 2005\projects\ex6\ex6\ex6.c(14) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\ my documents\visual studio 2005\projects\ex6\ex6\ex6.c(15) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\ my documents\visual studio 2005\projects\ex6\ex6\ex6.c(16) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\ my documents\visual studio 2005\projects\ex6\ex6\ex6.c(17) : error C2065: 'a' : undeclared identifier
1>c:\documents and settings\ my documents\visual studio 2005\projects\ex6\ex6\ex6.c(17) : error C2065: 'b' : undeclared identifier
1>c:\documents and settings\ my documents\visual studio 2005\projects\ex6\ex6\ex6.c(17) : error C2065: 'c' : undeclared identifier
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
int main()
{
FILE *f;
f=fopen("c:\\ware1.txt","r");
char a[20];
char b[20];
char c[20];
fscanf(f,"%20[^ ]%20[^ ]%20[^ ]%*c",a,b,c);
fclose(f);
return 0;
}
-
You have to provide a data type in here:
%20[^ ]
-
still i get the same errors
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
int main()
{
FILE *f;
f=fopen("c:\\ware1.txt","r");
char a[20];
char b[20];
char c[20];
fscanf(f,"%20[^ ]c%20[^ ]c%20[^ ]c%*c",a,b,c);
fclose(f);
return 0;
}
-
I don't know if it's legal to put nothing after the circumflex ^.
I assume you want it to avoid whitespace blanks or what?
-
the first line in the file is
W1 44444 WingThing 20
so i need to have
a=W1
b=44444
c=WingThing
why idont have that
i told it to stop on space char
??
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
int main()
{
FILE *f;
char a[20];
char b[20];
char c[20];
f=fopen("c:\\ware1.txt","r");
fscanf(f,"%20[^ ]%20[^ ]%20[^ ]%*c",a,b,c);
fclose(f);
return 0;
}
-
ok this works
but i am sure if it ignores one char at the end or justthe rest chars
i dont wont to stack the buffer with garbage
??
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
int main()
{
FILE *f;
char a[20];
char b[20];
char c[20];
f=fopen("c:\\ware1.txt","r");
fscanf(f,"%20s%20s%20s%*c",a,b,c);
fclose(f);
return 0;
}
-
Just use fscanf() to take in the W1, as a string. It will automatically stop at the first space it comes to.
Then use another %s for your next bit, etc.
-
but i am sure if it ignores one char at the end or justthe rest chars
i dont wont to stack the buffer with garbage
??
-
I wouldn't do the "ignore" thing. Take in what you want, and then handle it in the buffer for any particulars. Don't ask too much from fscanf() - it's liable to fail and leave your program mangled.
-
does fscanf self progessing on the file?
-
Yes, it moves the file pointer as it scans, if that's what you are asking.
-