SlideShare a Scribd company logo
I need some help to correct this code
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.
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 <ctype.h>
#include <string.h>
#include <stdio.h>
int nextWhite(const char* str)
{
int i, result = -1;
for (i = 0; result < 0 && str[i] != '0'; i++) {
if (isspace(str[i]))
{
result = i;
} }
return (result < 0) ? i : result; }
int isNumber(const char* str, const int len)
{
int i, result = 1;
for (i = 0; i < len && result; i++)
{
result = result && isdigit(str[i]);
}
return result; }
struct StringIndex indexString(const char* str)
{
struct StringIndex result = { {0}, {0}, {0}, 0, 0, 0 }; int i, sp;
strcpy(result.str, str); if (str[0] != '0')
{
result.lineStarts[0] = 0;
result.numLines = 1; }
for (i = 0; str[i] != '0'; i++)
{
while (str[i] != '0' && isspace(str[i]))
{
if (str[i] == 'n')
{
result.lineStarts[result.numLines] = i + 1;
}
i++; }
sp = nextWhite(str + i);
if (isNumber(str + i, sp - i + 1))
{
result.numberStarts[result.numNumbers++] = i;
}
else
{
result.wordStarts[result.numWords++] = i;
}
i += sp - 1; }
return result; }
int getNumberLines(const struct StringIndex* idx)
{
return idx->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 < idx->numWords && wordNum >= 0)
{
start = idx->wordStarts[wordNum]; sp = nextWhite(idx->str + start); for (i = 0; i < sp; i++)
{
word[i] = idx->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 < idx->numNumbers && numberNum >= 0) {
start = idx->numberStarts[numberNum]; sp = nextWhite(idx->str + start);
for (i = 0; i < sp; i++)
{
word[i] = idx->str[start + i]; }
word[sp] = '0'; }
}
char* getLine(struct StringIndex* idx, int lineNum)
{
char* result = NULL;
if (lineNum < idx->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 <stdio.h>
#include "stringhelp.h" #include <string.h>
#include <ctype.h>
int main(void)
{
char testStr[] = { "This is an string with embedded newline
characters andn12345 numbers inside it as well 7890" };
struct StringIndex index = indexString(testStr); int i;
printf("LINESn");
for (i = 0; i < index.numLines; i++)
{
printUntil(index.str, index.lineStarts[i], 'n');
printf("n"); }
printf("nWORDSn");
for (i = 0; i < index.numWords; i++)
{
printUntilSpace(index.str, index.wordStarts[i]);
printf("n"); }
printf("nNUMBERSn");
for (i = 0; i < index.numNumbers; i++)
{
printUntilSpace(index.str, index.numberStarts[i]);
printf("n"); }
return 0; }

More Related Content

Similar to I need some help to correct this code Instructions The following progr.docx

#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
ajoy21
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
karmuhtam
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
ajajkhan16
 
C programming
C programmingC programming
C programming
Karthikeyan A K
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
bhim1213
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)
Dmitry Zinoviev
 
Pointer in C
Pointer in CPointer in C
Pointer in C
bipchulabmki
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
KamalSaini561034
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Object Oriented Programming using C++: Ch10 Pointers.pptx
Object Oriented Programming using C++: Ch10 Pointers.pptxObject Oriented Programming using C++: Ch10 Pointers.pptx
Object Oriented Programming using C++: Ch10 Pointers.pptx
RashidFaridChishti
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
Bhuvana Gowtham
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
yamew16788
 
strings
stringsstrings
strings
teach4uin
 
Keypoints c strings
Keypoints   c stringsKeypoints   c strings
Keypoints c strings
Akila Krishnamoorthy
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
fashioncollection2
 
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdfIN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
siva009113
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 

Similar to I need some help to correct this code Instructions The following progr.docx (20)

#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
C programming
C programmingC programming
C programming
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
 
C for Java programmers (part 3)
C for Java programmers (part 3)C for Java programmers (part 3)
C for Java programmers (part 3)
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Object Oriented Programming using C++: Ch10 Pointers.pptx
Object Oriented Programming using C++: Ch10 Pointers.pptxObject Oriented Programming using C++: Ch10 Pointers.pptx
Object Oriented Programming using C++: Ch10 Pointers.pptx
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
strings
stringsstrings
strings
 
Keypoints c strings
Keypoints   c stringsKeypoints   c strings
Keypoints c strings
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
 
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdfIN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 

More from Phil4IDBrownh

I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docxI have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
Phil4IDBrownh
 
I have also tried these combinations which apparently where wrong B-C-.docx
I have also tried these combinations which apparently where wrong B-C-.docxI have also tried these combinations which apparently where wrong B-C-.docx
I have also tried these combinations which apparently where wrong B-C-.docx
Phil4IDBrownh
 
I am looking at satellite images- I come across one and say that there.docx
I am looking at satellite images- I come across one and say that there.docxI am looking at satellite images- I come across one and say that there.docx
I am looking at satellite images- I come across one and say that there.docx
Phil4IDBrownh
 
I am trying to fill out a program where the method definitions will b.docx
I am trying  to fill out a program where the method definitions will b.docxI am trying  to fill out a program where the method definitions will b.docx
I am trying to fill out a program where the method definitions will b.docx
Phil4IDBrownh
 
I am having trouble with the math- Emily- who is single- has been offe.docx
I am having trouble with the math- Emily- who is single- has been offe.docxI am having trouble with the math- Emily- who is single- has been offe.docx
I am having trouble with the math- Emily- who is single- has been offe.docx
Phil4IDBrownh
 
Human Relations Planning Consider that the human resource manager of y.docx
Human Relations Planning Consider that the human resource manager of y.docxHuman Relations Planning Consider that the human resource manager of y.docx
Human Relations Planning Consider that the human resource manager of y.docx
Phil4IDBrownh
 
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS 2-.docx
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS  2-.docxHTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS  2-.docx
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS 2-.docx
Phil4IDBrownh
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docxHuckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
Phil4IDBrownh
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docxHuckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
Phil4IDBrownh
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docxHuckvale Corporation manufactures custom cabinets for kitchens- It use.docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docx
Phil4IDBrownh
 
Hypertrophy May be reversible Is organ growth due to increased cell ce.docx
Hypertrophy May be reversible Is organ growth due to increased cell ce.docxHypertrophy May be reversible Is organ growth due to increased cell ce.docx
Hypertrophy May be reversible Is organ growth due to increased cell ce.docx
Phil4IDBrownh
 
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docxHuman Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
Phil4IDBrownh
 
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docxHPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
Phil4IDBrownh
 
I'm not sure how to go about using the RE expression and finding the m.docx
I'm not sure how to go about using the RE expression and finding the m.docxI'm not sure how to go about using the RE expression and finding the m.docx
I'm not sure how to go about using the RE expression and finding the m.docx
Phil4IDBrownh
 
I was excited about my new assignment on a special department project-.docx
I was excited about my new assignment on a special department project-.docxI was excited about my new assignment on a special department project-.docx
I was excited about my new assignment on a special department project-.docx
Phil4IDBrownh
 
I selected a random sample of 10 individuals who completed the Class S.docx
I selected a random sample of 10 individuals who completed the Class S.docxI selected a random sample of 10 individuals who completed the Class S.docx
I selected a random sample of 10 individuals who completed the Class S.docx
Phil4IDBrownh
 
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docxI think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
Phil4IDBrownh
 
I tried doing this myself and got stuck sorting out retained earnings.docx
I tried doing this myself and got stuck sorting out retained earnings.docxI tried doing this myself and got stuck sorting out retained earnings.docx
I tried doing this myself and got stuck sorting out retained earnings.docx
Phil4IDBrownh
 
I selected a random sample of 10 individuals who completed the Class S (1).docx
I selected a random sample of 10 individuals who completed the Class S (1).docxI selected a random sample of 10 individuals who completed the Class S (1).docx
I selected a random sample of 10 individuals who completed the Class S (1).docx
Phil4IDBrownh
 
How many ways can two items be selected from a group of six items- Use.docx
How many ways can two items be selected from a group of six items- Use.docxHow many ways can two items be selected from a group of six items- Use.docx
How many ways can two items be selected from a group of six items- Use.docx
Phil4IDBrownh
 

More from Phil4IDBrownh (20)

I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docxI have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
I have also tried only B-C-D-E I got it wrong- Which ones are the corr.docx
 
I have also tried these combinations which apparently where wrong B-C-.docx
I have also tried these combinations which apparently where wrong B-C-.docxI have also tried these combinations which apparently where wrong B-C-.docx
I have also tried these combinations which apparently where wrong B-C-.docx
 
I am looking at satellite images- I come across one and say that there.docx
I am looking at satellite images- I come across one and say that there.docxI am looking at satellite images- I come across one and say that there.docx
I am looking at satellite images- I come across one and say that there.docx
 
I am trying to fill out a program where the method definitions will b.docx
I am trying  to fill out a program where the method definitions will b.docxI am trying  to fill out a program where the method definitions will b.docx
I am trying to fill out a program where the method definitions will b.docx
 
I am having trouble with the math- Emily- who is single- has been offe.docx
I am having trouble with the math- Emily- who is single- has been offe.docxI am having trouble with the math- Emily- who is single- has been offe.docx
I am having trouble with the math- Emily- who is single- has been offe.docx
 
Human Relations Planning Consider that the human resource manager of y.docx
Human Relations Planning Consider that the human resource manager of y.docxHuman Relations Planning Consider that the human resource manager of y.docx
Human Relations Planning Consider that the human resource manager of y.docx
 
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS 2-.docx
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS  2-.docxHTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS  2-.docx
HTML- CSS- Javascript- React- Redux--- Questions- 1- SASS and LESS 2-.docx
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docxHuckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (2).docx
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docxHuckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use (1).docx
 
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docxHuckvale Corporation manufactures custom cabinets for kitchens- It use.docx
Huckvale Corporation manufactures custom cabinets for kitchens- It use.docx
 
Hypertrophy May be reversible Is organ growth due to increased cell ce.docx
Hypertrophy May be reversible Is organ growth due to increased cell ce.docxHypertrophy May be reversible Is organ growth due to increased cell ce.docx
Hypertrophy May be reversible Is organ growth due to increased cell ce.docx
 
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docxHuman Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
Human Resource Management ed 16- Chapter 12- page 445 Houston is among.docx
 
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docxHPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
HPRS 2201 Chapter 4- Endocrine System Diseases and Disorders Course Ob.docx
 
I'm not sure how to go about using the RE expression and finding the m.docx
I'm not sure how to go about using the RE expression and finding the m.docxI'm not sure how to go about using the RE expression and finding the m.docx
I'm not sure how to go about using the RE expression and finding the m.docx
 
I was excited about my new assignment on a special department project-.docx
I was excited about my new assignment on a special department project-.docxI was excited about my new assignment on a special department project-.docx
I was excited about my new assignment on a special department project-.docx
 
I selected a random sample of 10 individuals who completed the Class S.docx
I selected a random sample of 10 individuals who completed the Class S.docxI selected a random sample of 10 individuals who completed the Class S.docx
I selected a random sample of 10 individuals who completed the Class S.docx
 
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docxI think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
I think 42- 43- and 44 are true- but not too sure- Need help with 41 a.docx
 
I tried doing this myself and got stuck sorting out retained earnings.docx
I tried doing this myself and got stuck sorting out retained earnings.docxI tried doing this myself and got stuck sorting out retained earnings.docx
I tried doing this myself and got stuck sorting out retained earnings.docx
 
I selected a random sample of 10 individuals who completed the Class S (1).docx
I selected a random sample of 10 individuals who completed the Class S (1).docxI selected a random sample of 10 individuals who completed the Class S (1).docx
I selected a random sample of 10 individuals who completed the Class S (1).docx
 
How many ways can two items be selected from a group of six items- Use.docx
How many ways can two items be selected from a group of six items- Use.docxHow many ways can two items be selected from a group of six items- Use.docx
How many ways can two items be selected from a group of six items- Use.docx
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 

I need some help to correct this code Instructions The following progr.docx

  • 1. I need some help to correct this code 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. 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.
  • 2. * @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
  • 3. * @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 <ctype.h> #include <string.h> #include <stdio.h> int nextWhite(const char* str) { int i, result = -1; for (i = 0; result < 0 && str[i] != '0'; i++) { if (isspace(str[i])) { result = i; } } return (result < 0) ? i : result; } int isNumber(const char* str, const int len)
  • 4. { int i, result = 1; for (i = 0; i < len && result; i++) { result = result && isdigit(str[i]); } return result; } struct StringIndex indexString(const char* str) { struct StringIndex result = { {0}, {0}, {0}, 0, 0, 0 }; int i, sp; strcpy(result.str, str); if (str[0] != '0') { result.lineStarts[0] = 0; result.numLines = 1; } for (i = 0; str[i] != '0'; i++) { while (str[i] != '0' && isspace(str[i])) { if (str[i] == 'n') { result.lineStarts[result.numLines] = i + 1; } i++; } sp = nextWhite(str + i); if (isNumber(str + i, sp - i + 1)) { result.numberStarts[result.numNumbers++] = i;
  • 5. } else { result.wordStarts[result.numWords++] = i; } i += sp - 1; } return result; } int getNumberLines(const struct StringIndex* idx) { return idx->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 < idx->numWords && wordNum >= 0) { start = idx->wordStarts[wordNum]; sp = nextWhite(idx->str + start); for (i = 0; i < sp; i++) {
  • 6. word[i] = idx->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 < idx->numNumbers && numberNum >= 0) { start = idx->numberStarts[numberNum]; sp = nextWhite(idx->str + start); for (i = 0; i < sp; i++) { word[i] = idx->str[start + i]; } word[sp] = '0'; } } char* getLine(struct StringIndex* idx, int lineNum) { char* result = NULL; if (lineNum < idx->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]);
  • 7. } 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 <stdio.h> #include "stringhelp.h" #include <string.h> #include <ctype.h> int main(void) { char testStr[] = { "This is an string with embedded newline characters andn12345 numbers inside it as well 7890" }; struct StringIndex index = indexString(testStr); int i; printf("LINESn"); for (i = 0; i < index.numLines; i++) { printUntil(index.str, index.lineStarts[i], 'n'); printf("n"); } printf("nWORDSn"); for (i = 0; i < index.numWords; i++) { printUntilSpace(index.str, index.wordStarts[i]); printf("n"); } printf("nNUMBERSn"); for (i = 0; i < index.numNumbers; i++)