



I need help with this code,
I'm stuck on it, please remember step 4, I'm very much stuck on
that part. It says something about putting how many times it
appears
SOLUTION :-
#include <string.h>
#include <stdbool.h>
#include <getopt.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct Node{
char* key;
int value;
struct Node* left;
struct Node* right;
}Node;
void removeEnterLine(char* line){
char* ptr=&(line[0]);
while(ptr!=NULL){
if((*ptr)=='\n'){
*ptr='\0';
break;
}
ptr++;
}
}
int strcmpCaseSensitive(char* str1,char* str2){
char* ptr1=str1;
char* ptr2=str2;
while(ptr1!='\0' && ptr2!='\0'){
if((*ptr1)>(*ptr2))
return 1;
else if((*ptr1)<(*ptr2))
return -1;
ptr1++;
ptr2++;
}
if(ptr1=='\0' && ptr2=='\0')
return 0;
else if(ptr1=='\0')
return -1;
else
return 1;
}
int strcmpCaseInsensitive(char* str1,char* str2){
char* ptr1=str1;
char* ptr2=str2;
while(ptr1!='\0' && ptr2!='\0'){
char ch1=*ptr1;
char ch2=*ptr2;
ch1=tolower(ch1);
ch2=tolower(ch2);
if(ch1>ch2)
return 1;
else if(ch1<ch2)
return -1;
ptr1++;
ptr2++;
}
if(ptr1=='\0' && ptr2=='\0'){
return 0;
}
else if(ptr1=='\0')
return -1;
else
return 1;
}
int compareStrings(char* str1,char* str2,bool caseSensitive){
if(caseSensitive==true){
return
strcmpCaseSensitive(str1,str2);
}else{
return
strcmpCaseInsensitive(str1,str2);
}
}
void insert(char* tmp,Node* root,bool caseSensitive){
Node* temp=root;
Node* parent=NULL;
while(temp!=NULL){
if(compareStrings(temp->key,tmp,caseSensitive)==0){
temp->value=temp->value+1;
return;
}else
if(compareStrings(temp->key,tmp,caseSensitive)>0){
parent=temp;
temp=temp->left;
}else{
parent=temp;
temp=temp->right;
}
}
Node* newest=(Node*)malloc(sizeof(Node)*1);
newest->left=NULL;
newest->right=NULL;
newest->key=tmp;
newest->value=1;
if(compareStrings(parent->key,tmp,caseSensitive)>0){
//printf("left\n");
parent->left=newest;
}else{
//printf("right\n");
parent->right=newest;
}
}
void inorder(Node* root){
if(root==NULL)
return;
inorder(root->left);
int i;
for(i=1;i<=root->value;i++)
printf("%s\n", root->key);
inorder(root->right);
}
int main(int argc,char** argv){
bool caseSensitive=false;
char* output="";
char* input="";
int c;
while((c=getopt(argc,argv,"co:"))!=-1){
switch(c){
case 'c':
caseSensitive=true;
break;
case
'o':
output=optarg;
break;
}
}
int size=100000;
char** arr=(char**)(malloc(sizeof(char*)*size));
int index;
for (index = optind; index < argc; index++){
input=argv[index];
}
int ind=0;
if(strcmp(input,"")==0){ //std input
size_t line_size;
printf("Enter strings line by
line\n");
char*
line=(char*)malloc(sizeof(char)*100);
while(getline(&line,&line_size,stdin)!=-1){
if(strcmp(line,"\n")==0)
break;
removeEnterLine(line);
arr[ind++]=line;
line=(char*)malloc(sizeof(char)*100);
}
}else{
FILE *file = fopen(input, "r");
char*
line=(char*)malloc(sizeof(char)*100);
size_t line_size;
while(getline(&line,&line_size,file)!=-1){
removeEnterLine(line);
arr[ind++]=line;
line=(char*)malloc(sizeof(char)*100);
}
}
int j;
// for(j=0;j<ind;j++)
// printf("%s\n", arr[j]);
int sizeTree=0;
Node* root;
for(j=0;j<ind;j++){
char* tmp=arr[j];
if(sizeTree==0){
Node*
newest=(Node*)malloc(sizeof(Node)*1);
newest->key=tmp;
newest->value=1;
newest->left=NULL;
newest->right=NULL;
root=newest;
}else{
insert(tmp,root,caseSensitive);
}
sizeTree++;
}
inorder(root);
return 0;
}
sample input:
hello
good
boy
dude
dude
//make sure there is \n line after last word in input file
I need help with this code, I'm stuck on it, please remember step 4, I'm very...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...
Would appreciate the answer in the Java coding language please
and thank you!
10d 10h left Java 7 1. Check the Structure Autocomplete Ready 1 > import java.io.*;... 10 ALL A binary tree uses a multi-node data structure where each node may have 0 to 2 child nodes, and has one stored value, its node number in this case. A tree may either be: 11 class Result { * Complete the 'isValid' function below. • An empty tree, the root...
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...
C language huffman
This exercise will familiarize you with linked lists, which you will need for a subsequent programming Getting Started assignment Overview Requirements Getting Started Submit Start by getting the files. Type 264get hw13 and then cd hw13 from bash. Pre-tester You will get the following files: Q&A Updates 1. huffman.h: An empty header file, you have to define your own functions in this homework. 2. huffman.c: An empty c file, you have to define your own functions in...
I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...
Here you'll write the inorder traversal function in the header file "bst.h". Notice that the public inorder function calls a private recursive function _ inorder to do the actual traversal. This public-private strategy is the correct way to implement recursive functions, where the public function kicks off the recursion and the private function does the actual work. The public function is written for you, your job is to implement the private _ inorder function. he main program has been written...
Description: Merge two or more text files provided by the user into a new text file where the names of the text files to join and the output text file are provided to the program using command line arguments. Purpose: This application provides experience working with command line arguments, writing files to disk, reading files from disk, working with exceptions, and writing programs in C#/.NET. Requirements: Project Name: DocumentMerger2 Target Platform: Console Programming Language: C# In a previous challenge, Document...
Please submit only Python source code. 1. Arithmetic trees 50 marks You are given an input file with multiple pairs of input lines. The first line of each pair is a tree given as a predecessor array. The second line is the value at the corresponding node. Values at leaf nodes (nodes with no children) are integers. At non-leaf nodes, the two possible values are + or *. The tree represents an arithmetic expression where the value at a non-leaf...
Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...
Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...