In: Computer Science
Please write a C++ code that inputs a CSV file, asks the user if they'd like to remove certain words from the file, and removes the words from the file.
Please note that the CSV file has two columns, the first with the words, and the second with a count of how many times each word appears.
Remove certain words from the file, and removes the words from the file.
#include <iostream>
#include <cstring>
using
namespace
std;
int
main(){
char
string[100], pattern[100];
char
*ptr;
int
length;
cout << "Enter a
string\n"
;
cin.getline(string,
100);
cout << "Enter
string to remove\n"
;
cin.getline(pattern,
100);
length =
strlen
(pattern);
ptr =
strstr
(string, pattern);
strcpy
(ptr,
ptr+length);
cout << "Final
String\n"
<< string;
return(0);
}
Second with a count of how many times each word appears.
#include <bits/stdc++.h>
using
namespace
std;
int
countOccurences(
char
*str,
string
word)
{
char
*p;
vector<string> a;
p = strtok(str,
" "
);
while
(p
!= NULL)
{
a.push_back(p);
p
=
strtok
(NULL,
"
"
);
}
int
c = 0;
for
(
int
i = 0; i < a.size();
i++)
if
(word == a[i])
c++;
return
c;
}
int
main()
{
char
str[] =
"Count the Number of words you want to
search count the words "
;
string word =
"words"
;
cout <<
countOccurences(str, word);
return
0;
}
// Hence in Sample Input words are occuring two times
so , OUTPUT = 2.