Walt,
thank you for your response - Here is what _ have written so far:
(the contents of the header file getwsfield.h are:
Code:
#ifndef DATELIB_H /* define Bool only if needed (also in datelib.h) */
typedef enum { FALSE, TRUE } Bool;
#endif
/* getwsfield locates the specified field in the string s,
* where a field is a non-empty string surrounded by white space.
* The field is copied to buf, which has room for buflen bytes
* (including a terminating '\0'). Buflen must be at least 1.
* If the field doesn't exist, an empty string is placed in the buffer.
* If copy_to_end is false, only the requested field is copied,
* otherwise the rest of the string from the specified field onwards is copied.
*/
void getwsfield(char *s, int fieldnum, Bool copy_to_end,
char *buf, int buflen);
getwsfield.c:
Code:
* Purpose:Extracts a single field or field and trailing from a string into user-supplied buffer.*/
#include "getwsfield.h"
#include <ctype.h>
#include <string.h>
/* getwsfield locates the specified field in the string s,
* where a field is a non-empty string surrounded by white space.
* The field is copied to buf, which has room for buflen bytes
* (including a terminating '\0'). Buflen must be at least 1.
* If the field doesn't exist, an empty string is placed in the buffer.
* If copy_to_end is false, only the requested field is copied,
* otherwise the rest of the string from the specified field onwards is copied.
*/
void getwsfield(char *s, int fieldnum, Bool copy_to_end,
char *buf, int buflen , int s;
main ()
{
char *sp; /* Cursor to identify fields in s */
sp = s;
while (isspace(*sp))
sp++; /*isspace returns true if the character passed to it
(which could be a pointer dereference like *sp) is a whitespace character*/
}
char x,y,p,f;
{
char field[x];
char line[y];
GetField(n, line, field); /* n is field number to return */
}
/*Return the pointer to ws after the returned field*/
char * GetField(int f, char *ln, char *fld)
{
char *p;
int i;
p = ln;
/*SkipWhiteSpace will advance the pointer 'p' for each whitespace character*/
p = SkipWhiteSpace(p);
for (i = 1; i < f; i++)
{
/*GetField will advance the pointer 'p' for each nonwhitespace character and load
the character into the fld pointer*/
p = GetField(p, fld);
p = SkipWhiteSpace(p);
}
p = GetField(p, fld);
return 0;
}
When I tried to 'make' getwsfield.c, I got quite a few errors:
gcc -Wall -g -c getwsfield.c
getwsfield.c:23: conflicting types for `s'
getwsfield.c:22: previous declaration of `s'
getwsfield.c:25: parse error before "main"
getwsfield.c: In function `getwsfield':
getwsfield.c:27: number of arguments doesn't match prototype
getwsfield.h:22: prototype declaration
getwsfield.c:31: `s' undeclared (first use in this function)
getwsfield.c:31: (Each undeclared identifier is reported only once
getwsfield.c:31: for each function it appears in.)
getwsfield.c: At top level:
getwsfield.c:39: parse error before '{' token
getwsfield.c:41: variable-size type declared outside of any function
getwsfield.c:43: warning: type defaults to `int' in declaration of `GetField'
getwsfield.c:43: warning: parameter names (without types) in function declaratio
n
getwsfield.c:43: warning: data definition has no type or storage class
getwsfield.c:45: parse error before '}' token
getwsfield.c:49: conflicting types for `GetField'
getwsfield.c:43: previous declaration of `GetField'
getwsfield.c: In function `GetField':
getwsfield.c:55: warning: implicit declaration of function `SkipWhiteSpace'
getwsfield.c:55: warning: assignment makes pointer from integer without a cast
getwsfield.c:61: warning: passing arg 1 of `GetField' makes integer from pointer
without a cast
getwsfield.c:61: too few arguments to function `GetField'
getwsfield.c:62: warning: assignment makes pointer from integer without a cast
getwsfield.c:64: warning: passing arg 1 of `GetField' makes integer from pointer
without a cast
getwsfield.c:64: too few arguments to function `GetField'
make: *** [getwsfield.o] Error 1
I understand some of these errors, but not c:55 onwards.
I was advised to use a scanf statement, after my isspace loop.. should I now use the statement after your skipwhitespace loop?
Thanks again,
Marko