Skip to content

Instantly share code, notes, and snippets.

@FabiolaRamirez
Created December 6, 2017 16:26
Show Gist options
  • Select an option

  • Save FabiolaRamirez/ebe09ad3ee3311fec9e68b64bc4f35a4 to your computer and use it in GitHub Desktop.

Select an option

Save FabiolaRamirez/ebe09ad3ee3311fec9e68b64bc4f35a4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
/*void parseStrings((const char**) ops){
for (auto& op : ops)
{
cout << op << endl;
}
}*/
int main()
{
const char* ops[] = {
"a = 1",
"b = 25",
"c = \"Hello world\"",
"d = a + b",
"e = d + c",
"f = 3.141592653",
"g = true",
"h = !g",
"i = treu",
"variable_1 = e",
"variable_2 =",
"= 256",
"",
"variable_3=a ",
"variable_4 =f",
"variable_5= c + \" of c++ programmers\"",
"variable_5 = variable_5 + \" using c++17\"",
"variable_5 = 4",
"="
};
//char* vecE[25];
//strcpy( vecE, ops);
//cout<<strlen(vecE)<<endl;
//char newArray[40];
for (auto& op : ops)
{
char a[40];
strcpy( a, op);
for (int i = 0; i < strlen(a); i++) {
if (a[i] == ' '){
a[i] = (char) 0;
}
}
string x;
x = (string) a;
//cout << x << endl;
}
//string s = "scott>=tiger";
//string delimiter = ">=";
//string token = s.substr(0, s.find(delimiter));
//cout << token <<endl;
string s = "scott>=tiger>=mushroom";
string delimiter = ">=";
size_t pos = 0;
string token;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
std::cout << token << std::endl;
s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;
//does not work
cout<<"deleting spaces from string: this is a test"<<endl;
string algo = "this is a test";
algo.replace(algo.begin(),algo.end(), ' ','x');
cout <<algo<<endl;
}
/*
//OUTPUT:
[OK] [a = 1]
[OK] [b = 25]
[OK] [c = "Hello world"]
[OK] [d = a + b]
[ERROR] [e = d + c] Msg: [Cannot apply operator+ on variables of different type]
[OK] [f = 3.141592653]
[OK] [g = true]
[OK] [h = !g]
[ERROR] [i = treu] Msg: [Unknown variable 'treu']
[ERROR] [variable_1 = e] Msg: [Unknown variable 'e']
[ERROR] [variable_2 =] Msg: [Syntax error]
[ERROR] [= 256] Msg: [Syntax error]
[ERROR] [] Msg: [Unsupported empty expression]
[OK] [variable_3=a ]
[OK] [variable_4 =f]
[OK] [variable_5= c + " of c++ programmers"]
[OK] [variable_5 = variable_5 + " using c++17"]
[ERROR] [variable_5 = 4] Msg: [variable_5 defined previously as 'string']
[ERROR] [=] Msg: [Syntax error]
********
a: [1]
b: [25]
c: [Hello world]
d: [26]
f: [3.141592653]
g: [true]
h: [false]
variable_3: [1]
variable_4: [3.141592653]
variable_5: [Hello world of c++ programmers using c++17]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment