Write a program that reads a text of strings from a text file (i.e. example.txt)
ID: 3643792 • Letter: W
Question
Write a program that reads a text of strings from a text file (i.e. example.txt),tokenizes each string (i.e. each line in the text file represents a string) into an array of
words (use white space as a separator), sorts the array using the insertion or bubble
sort, and displays the sorted array (one word per line). The array can be declared as
follows: char str[SIZE][N]; where SIZE and N are defined as preprocessing
directives (100 and 25 respectively). Make sure you use appropriate string functions
to read a string from the file, to perform assignment; comparison, to tokenize a string,
etc
Explanation / Answer
#include #include #include #define SIZE 100 #define n 25 void token(char arr[SIZE][n], char str[200], int &s); void sort(char arr[SIZE][n],int s); void find(char arr[SIZE][n], char str[25], int s); int main() { char arr[SIZE][n]; char str[25]; int s=0; ifstream fin; fin.open("d:/inputstr.txt"); while(!fin.eof()) { fin>>str; token(arr,str,s); } coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.