[Solved] Why sscanf is not handling or ignoring spaces in c++?

Why sscanf is not handling or ignoring spaces in c++? How else should sscanf seperate words/tokens? From its documentation: [“%s”] matches a sequence of non-whitespace characters (a string) I don’t think you can handle this with sscanf or in a one-liner at all. You could do this with std::string::find_first_of and std::string::substr Edit: std::regex_match might be … Read more

[Solved] How to run the sin(double x) method in C

double sin(double x) Is a function declared in the math.h header. It can be used anywhere you’d like – in main() or in any other function you write that is called within main(). However, the way you show it called in main will not do anything useful. The sin() function takes a double as an … Read more

[Solved] How to delete the book that have been input and how to make the title, language, and name doesn’t error if we put space on it? [closed]

If you want to enter data per line, here is an example: class Book { int number; int year; std::string language std::string name; std::string title; public: friend std::istream& operator>>(std::istream& input, Book& b); //… }; std::istream& operator>>(std::istream& input, Book& b) { std::string text_line; std::getline(input, text_line); std::istringstream text_stream(text_line); text_stream >> b.number >> b.year >> b.language >> b.name … Read more

[Solved] I dont understand error “definition of implicity-declared ‘Clothing::Clothing()’

The error is: you declared a destructor but you didn’t define it. Add a definition for the destructor or define it as default: #ifndef CLOTHING_H_ #define CLOTHING_H_ #include <string> #include <iostream> using namespace std; class Clothing { private: int gender; int size; string name; public: Clothing(); Clothing(const Clothing &t); Clothing(int gender, int size, string name); … Read more

[Solved] How to chain and serialize functions by overloading the | operator

First I assume you have some basics that look like this #include <iostream> struct vec2 { double x; double y; }; std::ostream& operator<<(std::ostream& stream, vec2 v2) {return stream<<v2.x<<‘,'<<v2.y;} //real methods vec2 translate(vec2 in, double a) {return vec2{in.x+a, in.y+a};} //dummy placeholder implementations vec2 rotate(vec2 in, double a) {return vec2{in.x+1, in.y-1};} vec2 scale(vec2 in, double a) {return … Read more

[Solved] How to sort structs from least to greatest in C?

fix like this #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFF_SIZE 32 #define STRUCT_SIZE 512 struct info { char name[BUFF_SIZE]; char stAddress[BUFF_SIZE]; char cityAndState[BUFF_SIZE]; char zip[BUFF_SIZE]; }; void selectionSort(struct info *ptrStruct[], int size);//! int main(void){ int count, size;//! char buffer[600]; struct info *ptrStruct[STRUCT_SIZE]; for (count = 0; count < STRUCT_SIZE; count++){ ptrStruct[count] = (struct info*) … Read more

[Solved] [] operator in std::map is giving me segmentation fault [closed]

Maybe your myMap is no longer accessible. For instance, it might be a reference to a deleted pointer, or, much more probable, a member variable of an already deleted class: class MyClass { public: selfInsert(std::string myKey) { if(!myKey.empty()) { myMap[myKey] = this; } } private: std::map<std::string, myClass*> myMap; } int main() { MyClass *a = … Read more

[Solved] Can’t find issue with “Too many arguments for format” [closed]

all you have to do is correct the %l(there is not such a specifier), you probably should have used %ld. char *buildStatus() { struct rusage *usage = malloc(sizeof(struct rusage)); int usageRet = getrusage(RUSAGE_SELF, usage); if (usageRet == -1) { perror(“RUSAGE fail”); exit(EXIT_FAILURE); } long unsigned cpuTime = (usage->ru_utime).tv_sec + (usage->ru_stime).tv_sec; long memUsed = get_memory_usage_linux(); unsigned … Read more