Can't solve problems! please Help

Joined
Sep 26, 2022
Messages
1
Reaction score
0
Hi everyone :) I am new to coding. Have a homework for programming paradigms but can't solve this problems. Will be extremely grateful if anyone can help me. I need codes of it.
Thank you in advance


3 scan token (4 points)
With the goal of making an improved function that performs the same type of tokenization
as strtok without its awkward design, you are to write the function scan token. The required
prototype for scan token is:
b o ol s c a n t o k e n ( const char ∗∗ p inpu t , const char ∗ d e l i m i t e r s ,
char bu f [ ] , s i z e t b u fl e n )
5
The function scans the input string to determine the extent of the token using the delimiters
as separators and then writes the token characters to buf, making sure to terminate with a null
char. The function returns true if a token was written to buf, and false otherwise.
Specific details of the function’s operation:
• Your implementation of scan token should take the same general approach as strtok,
meaning it can (and should!) use the handy < string.h > functions such as strspn and
strcspn, but it should not replicate the bad parts of its design, which is to say no static
variables, no weird use of the input argument to pass information across a sequence of
calls, and should not destroy the input string.
• The function separates the input into tokens in the same way that strtok does: it scans the
input string to find the first character not contained in delimiters. This is the beginning
of the token. It scans from there to nd the first character contained in delimiters. This
delimiter (or the end of the string if no delimiter was found) marks the end of the token.
• Note that the parameter p input is a char ** . This is a pointer argument that is being
passed by reference. The client passes a pointer to the pointer to the first char of the
input string. The function will update the pointer held by p input to point to the next
character following the token that was just scanned.
• buf is a fixed-length array to store the token and buflen is the length of the buffer.
scan token should not write past the end of buf. If a token does not fit in buf, the
function should write buflen - 1 characters into buf, write a null byte in the last slot, and
the pointer held by p input should be updated to point to the next character following
the buflen - 1 characters in the token. In other words, the next token scanned will start
at the first character that would have overflowed buf.
Consider this sample use of scan token:
const char ∗ i n p u t = ” super−duper−awesome−m a g ni fi c e n t ” ;
char bu f [ 1 0 ] ;
const char ∗ rem ainin g = i n p u t ;
while ( s c a n t o k e n (& remaining , ”−” , buf , s i z e o f ( bu f ) ) ) {
p r i n t f ( ”Next token : %s \n” , bu f ) ;
}
Running the above code produces this output:
Next token: super
Next token: duper
Next token: awesome
Next token: magnifice
Next token: nt
Write your implementation of scan token in the scan token.c file. You can test it using our
provided tokenize.c program:
$ ./tokenize " -" "hello I am a C-string"
Tokenized: { "hello" "I" "am" "a" "C" "string" }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,707
Messages
2,569,343
Members
44,635
Latest member
Matt231

Latest Threads

Top