Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code in text format stringhelp.h #pragma once #ifndef STRINGHELP_H #define STRINGHELP_H #define MAX_STRING_SIZE 511 #define MAX_INDEX_SIZE 100 #define MAX_WORD_SIZE 23 struct StringIndex

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Here is the code in text format

stringhelp.h #pragma once #ifndef STRINGHELP_H #define STRINGHELP_H #define MAX_STRING_SIZE 511 #define MAX_INDEX_SIZE 100 #define MAX_WORD_SIZE 23 struct StringIndex { char str[MAX_STRING_SIZE + 1]; int wordStarts[MAX_INDEX_SIZE]; int lineStarts[MAX_INDEX_SIZE]; int numberStarts[MAX_INDEX_SIZE]; int numWords, numLines, numNumbers; }; /** * Return the index of the next whitespace. * @param str - the string to search * @returns the index of the next white space or the position of the string terminator. */ int nextWhite(const char* str); /** * Return true if the string contains only digits. * @param str - the string to check * @param len - the number of characters to check * @returns true if the string is only digits. */ int isNumber(const char* str, const int len); /** * Build an index for a string showing the start of the lines, * words, and numbers in the string. * @param str - the string to search * @returns the index of the next white space or -1 if there is none. */ struct StringIndex indexString(const char* str); /** * Return the number of lines in the index. * @param idx - the index to get the number of lines in it * @returns the number of lines in the index */ int getNumberLines(const struct StringIndex* idx); /** * Return the number of words in the index. * @param idx - the index to get the number of words in it * @returns the number of words in the index */ int getNumberWords(const struct StringIndex* idx); /** * Return the number of numbers in the index. * @param idx - the index to get the number of numbers in it * @returns the number of numbers in the index */ int getNumberNumbers(const struct StringIndex* idx); /** * Return the nth word from the index * @param word - where the result will be placed * @param idx - the index to use * @param wordNum - the index of the word to retrieve * @returns the word or an empty string if index is invalid */ void getWord(char word[], const struct StringIndex* idx, int wordNum); /** * Return the nth number from the index * @param word - where the result will be placed * @param idx - the index to use * @param wordNum - the index of the number to retrieve * @returns the number or an empty string if index is invalid */ void getNumber(char word[], const struct StringIndex* idx, int numberNum); /** * Return a pointer to the start of a line * @param idx - the index to use * @param lineNum - the index of the line to retrieve * @returns a pointer to the start of the line */ char* getLine(struct StringIndex* idx, int lineNum); /** * Prints characters until the terminator is found. * @param s - the string to print * @param start - the index to start printing * @param terminator - the character to stop printing at when encountered. */ void printUntil(const char* s, const int start, const char terminator); /** * Prints characters until a space is found. * @param s - the string to print * @param start - the index to start printing */ void printUntilSpace(const char* s, const int start); #endif stringhelp.c #define _CRT_SECURE_NO_WARNINGS #include "stringhelp.h" #include #include #include int nextWhite(const char* str) { int i, result = -1; for (i = 0; result numLines; } int getNumberWords(const struct StringIndex* idx) { return idx->numWords; } int getNumberNumbers(const struct StringIndex* idx) { return idx->numNumbers; } void getWord(char word[], const struct StringIndex* idx, int wordNum) { int i, sp, start; word[0] = '\0'; if (wordNum numWords && wordNum >= 0) { start = idx->wordStarts[wordNum]; sp = nextWhite(idx->str + start); for (i = 0; i str[i]; } word[sp] = '\0'; ((struct StringIndex*)idx)->numWords--; } } void getNumber(char word[], const struct StringIndex* idx, int numberNum) { int i, sp, start; word[0] = '\0'; if (numberNum numNumbers && numberNum >= 0) { start = idx->numberStarts[numberNum]; sp = nextWhite(idx->str + start); for (i = 0; i str[start + i]; } word[sp] = '\0'; } } char* getLine(struct StringIndex* idx, int lineNum) { char* result = NULL; if (lineNum numLines && lineNum >= 0) { result = idx->str + idx->lineStarts[lineNum]; } return result; } void printUntil(const char* s, const int start, const char terminator) { int i; for (i = start; s[i] != '\0' && s[i] != terminator; i++) printf("%c", s[i]); } void printUntilSpace(const char* s, const int start) { int i; for (i = start; s[i] != '\0' && !isspace(s[i]); i++) printf("%c", s[i]); } main.c #define _CRT_SECURE_NO_WARNINGS #include #include "stringhelp.h" #include #include int main(void) { char testStr[] = { "This is a string with embedded newline characters and 12345 numbers inside it as well 7890" }; struct StringIndex index = indexString(testStr); int i; printf("LINES "); for (i = 0; i SFT221 - Workshop 5 Learning Outcomes - Learn to use the Visual Studio debugger, - Learn generaldebugging concepts, - Learn debugging techniques. Instructions The following program takes a string and builds an index of it. The index indicates the: - Start of each line in the string. - Start of each word in the string, - Start of each number in the string. Unfortunately, a junior developer worked on the code and there are bugs in it. Your job is to use the Visual Studio debugger to find and fix the bugs in the code. You should only use the debugger to find the bugs - DO NOT USE print sta tements or other techniques. The purpose of this workshop is to get experience with the debugger. Take notes as to which debugging tools you use as there will be questions about which ones you used to find each bug later. stringhelp.h *pragma once \#ifndef STRINGHELP_H \#define STRINGHELP_H \#define MAX_STRING_SIZE 511 \#define MAX_INDEX_SIZE 100 Hdefine MAX_WORD_SIZE 23 struct StringIndex \{ char str[MAX_STRING_SIZE +1]; int wordStarts[MAX_INDEX_SIZE]; int lineStarts [MAX_INDEX_SIZE]; int numberStarts [MAX_INDEX_SIZE]; int numbords, numlines, numNumbers; 7i: /k * Return the index of the next whitespace. * Gaparam str - the string to search * @returns the index of the next white space or the position of the string terminator. * / int nexthhite(const char* str); /kk * Return true if the string contains only digits. * Eparam str - the string to check * eparan len - the number of characters to check * @returns true if the string is only digits. * / int isNumber(const char* str, const int len); /k k * Build an index for a string showing the start of the lines, * words, and numbers in the string. * aparam str - the string to search * Qreturns the index of the next white space or -1 if there is none. */ struct StringIndex indexstring(const char* str); / * Return the number of lines in the index. * aparam idx - the index to get the number of lines in it * Qreturns the number of lines in the index */ int getNumberLines (const struct StringIndex* idx); / * Return the number of words in the index. * Qparam idx - the index to get the number of words in it * Qreturns the number of words in the index */ int getNumberwords (canst struct StringIndex* idx); / * Return the number of numbers in the index. * aparan idx - the index to get the number of numbers in it * ereturns the number of numbers in the index */ int getNumberNumbers(const struct StringIndex* idx); / * Return the nth word from the index * eparan word - where the result will be placed * eaparan idx - the index to use * aparan wordNum - the index of the word to retrieve * areturns the word or an empty string if index is invalid */ void getword(char word[], const struct StringIndex* idx, int wordNum); / * Return the nth number from the index * eparam word - where the result will be placed * Qparam idx - the index to use * Qaaran wordNum - the index of the number to retrieve * Qreturns the number or an empty string if index is invalid / void getNumber(char word[], const struct StringIndex* idx, int numberNum); f * Return a pointer to the start of a line * Qparam idx - the index to use * aparam lineNum - the index of the line to retrieve * areturns a pointer to the start of the line */ char* getLine(struct StringIndex* idx, int lineNum); * Prints characters until the terminator is found. * Qparan 5 - the string to print * Qparam start - the index to start printing * Qaram terminator - the character to stop printing at when encountered. / void printUntil(const char* 5 , const int start, const char terminator); /4 * Prints characters until a space is found. * Qparan s - the string to print * Qaparam start - the index to start printing / void printUntilSpace(const char* s, const int start); \#endif stringhelp.c Hdefine_CRT_SECURE_NO_WARNINGS \#include "stringhelp.h" *include h \#include int nexthhite(const char* str) \{ int i, result =1; for (i=0; result

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

why the actual size not 8 0 GB in Virtual Machine + Cyber Security

Answered: 1 week ago