I have this code in C++ but I dont know ho to do it in C. Any Help?
Code #1:
#include <vector> // for vector
#include <sstream> // for stringstream
#include <iostream>
#include <string>
int main()
{
std::stringstring ss;
std::string input, temp;
std::vector<string>; comand;
std::cout << ": ";
std::getline(cin, input);
ss << input;
// brak up line and put each part into the vector
while( ss >> temp)
{
comand.push_back(temp);
}
// display vector
for(size_t i = 0; i < comand.size(); i++)
std::cout << comand[i] << std::endl;
std::cin.get(); // pause program
return 0;
}
Code 2:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
vector <string> split(const string& s, char delim)
{
vector <string> result;
istringstream iss(s);
string part;
while(getline(iss, part, delim))
result.push_back(part);
return result;
}
int main()
{
ifstream in("test.txt");
if(in)
{
string line;
string isbn;
cout<<"\n\n\tEnter ISBN: ";
cin>>isbn;
while(getline(in, line))
{
vector <string> parts = split(line, ' ');
if (parts.at(0) == isbn)
{
cout<<"Book Number: "<<parts.at(0)<<endl;
cout<<"Book Title: "<<parts.at(1)<<endl;
cout<<"Book Author: "<<parts.at(2)<<endl;
}
}
}
}
I think that you would have to use dynamic memory but I dont know how to implement it.