It's always better to break down a task into smaller tasks
Maybe you can work with this skeleton
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void read_file(char* name){
...
Type: Posts; User: thmm
It's always better to break down a task into smaller tasks
Maybe you can work with this skeleton
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void read_file(char* name){
...
A simple example might make it easier.
#include <stdio.h>
typedef struct
{
int X, Y;
} Point;
Country isn't a float, it's a string and you should read it as a string.
Also you should skip the first line.
Do you have to use different arrays ? It would be easier to use an array of structs.
...
Yor getFile could be simpler.
vector<double> getFile() {
vector<double> input_from_file;
fstream loaded_file("unsorted_numbers_short.dat");
if (!loaded_file) {
cout << "File not...
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