More in the spirit of C++ is to use std::array.
Type: Posts; User: thmm
More in the spirit of C++ is to use std::array.
@Schol-R-LEA-2,
yes, it's not 100% what you look for. Maybe you can add to it or modify it. Might be easier than starting from scratch.
I think it's useful, but sth. like this exists already.
GitHub - boostorg/safe_numerics: Replacements to standard numeric types which throw exceptions on errors
Safe Numerics - develop
Your data looks like JSON, so using a JSON library might be a good idea.
I see. So it's more an API problem.
Shouldn't the compiler be able to warn when passing a const char* to a function that accepts a char* ?
I would use this structure
// compile with -std=c99
#include <stdio.h>
#include <stdbool.h>
int main()
{
I would recommend "Programming Windows" by Charles Petzold. It's still the classic about Windows Programming.
https://www.amazon.co.uk/gp/product/B00JDMP71S/ref=dbs_a_def_rwt_hsch_vapi_tkin_p1_i2
while (gals != -1)
This will never be true because gals is an unsigned int.
Add a simple print statement after L23 to see the value of gals when you enter -1
Have a look at the answers there.
Why you don't want to use an IDE like MonoDevelop.
MonoDevelop | MonoDevelop
Why don't you use .NET Core? It runs on Windows, Mac and Linux. I am not sure if...
It's the same code you posted + the include.
You also need to set the C++ Language Standard
16476
You also need to include <ranges>, then it works with my VS2019
The code you found looks very c-ish.
It's much easier to check.
bool is_palindrome(const std::string& s){
std::string tmp(s.rbegin(), s.rend());
return s == tmp;
}
I have difficulty understanding what you want to do.
It seems you want to implement different categories, but how do they differ. ?
Implementing a product with a category shouldn't be so...
BTW. According to C++ guidelines raw pointers should not be used.
C++ Core Guidelines
So a better option is to use either std::unique_ptr or std::shared_ptr.
For a kind of static polymorphism...
You can't pass variables to a template because everything must be known at compile time.
You specify types or constant numbers, like:
std::vector<int> v;
std::array<int, 3> a;
ptr = malloc( 2 * sizeof(*ptr));
Your code and your intention don't match.
Don't you see the problem ?
ptr++; This looses the address of the original pointer.
Good idea.
Using an array of counters would be an alternative - works also for unsorted arrays.
#include <stdio.h>
#define NUM_DIGITS 9
int main ()
{
int Digits[NUM_DIGITS] = {1, 1, 1, 2,...
You don't need to store the text. You can read the file char by char and check if if is a letter.
#include <iostream>
#include <fstream>
int main()
{
if(std::ifstream input{__FILE__})
clang and GCC have a memory sanitizer - have you tried that ?
gcc comes with sanitizer tool to use - TechnologyRelated
What errors do you get ?
I would break up the code into 2 different functions. One to calculate for men and one for women
Well, you know how to print a prompt and get user input already. Just do it again.
To compare the input with some value you can use strcmp from string.h
One problem with mmap is that it is not standard, it's Linux only.
If you don't bother about compatibility then go ahead.
BTW. Have you decided to use C instead of C++ ?
I noticed you also have...
When casting you might get over- / underflow problems. To avoid this problem the GSL has a type gsl::narrow that detects this problem.
GitHub - gsl-lite/gsl-lite: gsl-lite – A single-file...