Lv 31,408 points

Fadi

Favorite Answers30%
Answers394
  • annoying C++ gcc warning message?

    I've written the following program to match regular expressions in C++

    #include <regex.h>

    #include <iostream>

    using namespace std;

    /*

    * Match string against the extended regular expression in

    * pattern, treating errors as no match.

    *

    * return true for match, false for no match

    */

    bool match(const char *string, char *pattern)

    {

    int status;

    regex_t re;

    if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0)

    return false; /* report error */

    status = regexec(&re, string, (size_t) 0, NULL, 0);

    regfree(&re);

    if (status != 0) {

    return false; /* report error */

    }

    return true;

    }

    int main()

    {

    string str = "def fadi 100";

    bool matchExp = match(str.c_str(), "^[Dd][Ee][Ff][' '\t]+[A-z]+([,])?[' '\t]+[0-9]+$");

    cout << (matchExp == true ? "Match": "No match") << endl;

    }

    The program works fine just as expected, but when I compile the code using gcc with the -Wall -Werror arguments (Linux environment), I get a very annoying warning message saying the following:

    main.cpp: In function ‘int main()’:

    main.cpp:33:90: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

    Is there a way to force the compiler to believe that str.c_str() is the same as char * str? if so, how?

    4 AnswersProgramming & Design8 years ago
  • C++11 standard hastable implementation?

    I've once been told that C++11 provides a standard implementation of a hashtable class. is that true? if so, where could I find the source code?

    1 AnswerProgramming & Design8 years ago
  • arithmetic expression validation with regex?

    I am not sure if this is even possible in regex as none of my reference books had an answer to my question, but I thought I'd go ahead and give it a shot here.

    My question in the title is not really expressive so I'll explain in detail what I am trying to achieve here.

    Say you have the following arithmetic expression:

    10 + 20 * (2 * 13)

    or something like

    a - b * ((a/2) * 2)

    where a and b are guaranteed to be some numbers (most likely always integers). I was wondering if there's a way to have an IF-AND-ONLY-IF regex expression that will basically say "if there's an open parenthesis, there has to be a closing parenthesis somewhere in the expression. is this doable?

    3 AnswersProgramming & Design8 years ago
  • does protein really make a difference?

    It's been almost two years since I decided to quit taking any artificial protein and focus more on exercising harder and eating health(ier). and I have still been able to build muscles. So I was wondering what difference protein really makes (if any)!

    1 AnswerDiet & Fitness8 years ago
  • any way to increase ps3 memory (RAM)?

    as you may (or may not) already know, PS3 comes with a built-in 512mb of RAM. Is there a way to increase the memory?

    3 AnswersPlayStation8 years ago
  • through vs by -- details inside?

    Is your privacy and lack of security worth enjoying the convenience brought to you through technology?

    or

    Is your privacy and lack of security worth enjoying the convenience brought to you by technology?

    Which one sounds better to your ear?

    1 AnswerLanguages8 years ago
  • g++ compiler optimization options?

    I am not very familiar with how g++ actually generates a more optimized code at the programmer's request. However I know the more optimized code generated, the smaller the size of the executable will be due to a better cache performance, but does that mean an even smaller amount of RAM will be used by the program? I am building a mini-assembler, and it seems that the computer starts to slow down exponentially if an unconditional branch instruction is executed, so I thought letting the compiler optimize my code my solve the problem before I go ahead and mess with my source code

    1 AnswerProgramming & Design8 years ago
  • question regarding the raspberry pi?

    it seems that whenever I install a new OS image on a SD card, no matter how big the size is, I can only aggess 992MB of it when the system boots up. The rest of the memory is just lost. Anyone know how this lost portion of the memory can be allocated?

    P.S. I tried sudo fdish -l already, and it didn't come up on the list.

    3 AnswersOther - Hardware8 years ago
  • Maximum memory an i5 iMac can handle?

    I have an iMac with the following specs:

    Processor: Intel(R) Core(TM) i5 CPU 760 @ 2.80GHz 2.79 GHz

    Memory: 4GB

    and I have been thinking upgrading my RAM. Since money isn't an object, I was thinking of going 32GB, but I really don't know if my computer (processor to be more specific) can handle it. I looked up online and there didn't seem to be a straight answer. Please share your personal experience.

    Any contribution made to answer the question will be highly appreciated.

    2 AnswersDesktops8 years ago
  • determine online file size in bash (Linux)?

    I was wondering if there's a Linux utility to find the size of a file located on a public/private server. Any help would be highly appreciated.

    2 AnswersComputer Networking8 years ago
  • Question regarding electricity?

    I've always wondered, before electricity, how did people charge their cell phones and iPods!! Best question gets 10 stars :-)

    1 AnswerEngineering8 years ago
  • Netgear router requires the existence of another modem?

    I have been having internet speed issues at home. I called my internet provider, at&t, and they suggested that my outdated router (almost 4 years old now) is what's causing the issues, so I went ahead and bought a new router (Netgear N600). However, when I did the set-up, I found out that the new router has to receive its input from an existing modem in order to function!! I am so confused now. So what is the point if having a new router if it's going to depend on the old modem to suply internet? What if my old router fails? The user manual's help page is next to no help, so I thought i'd post a question on here and see if anyone would clarify

    3 AnswersComputer Networking8 years ago
  • What does 'so many man made ideals.' mean?

    Read the phrase on a friend's status. I have no idea what this could possibly mean. I don't want to ask him so I don't sound like an idiot. anyone have any idea?

    2 AnswersLanguages8 years ago
  • C/C++ IDE(s) for Linux?

    Other than CodeBlocks, what is/are some good C/C++ IDE(s) for Linux? Share your personal experience please.

    1 AnswerProgramming & Design8 years ago
  • am I the only one having connectivity issues with my android device?

    is anyone else having issues with their android-based tablet? if so, what are you doing to handle the problems?

    2 AnswersOther - Hardware9 years ago
  • what's the most efficient way to sort large arrays and linked lists?

    and by 'efficient' i slightly mean fastest

    1 AnswerProgramming & Design9 years ago
  • how to check if a binary search tree is full?

    I'm working on a project with a friend of mine. I have written the code so far

    #include <iostream>

    #include "tree.h"

    using namespace std;

    // searchTree

    //

    // Purpose: initalize the search tree

    //

    // Precondition: none

    // Postcondition: initalized empty tree

    //

    searchTree::searchTree()

    {

    root = NULL;

    }

    // ~searchTree

    //

    // Purpose: release all space allocated to the search tree

    //

    // Precondition: properly initialized search tree exist and is referenced by the internal pointer root

    // Postcondition: all space allocated to the tree is released

    //

    searchTree::~searchTree()

    {

    destroy( root );

    }

    // searchTree

    //

    // Purpose: copy a searchTree

    //

    // Precondition: properly initialized search tree exist and is referenced by the internal pointer root

    // Postcondition: a copy of the search tree is stored in "this" searchTree

    //

    searchTree::searchTree( const searchTree& t )

    {

    root = copy( t.root );

    }

    // operator=

    //

    // Purpose: assign a searchTree to another searchTree

    //

    // Precondition: properly initialized search tree exist and is referenced by the internal pointer root

    // Postcondition: a copy of the search tree is created and sotred in "this" searchTree

    //

    searchTree& searchTree::operator=( searchTree& t )

    {

    if ( this != &t )

    {

    destroy( root );

    root = copy( t.root );

    }

    return *this;

    }

    // insert

    //

    // Purpose: insert a node containing x into the search tree, if it does not already exists

    //

    // Precondition: properly initialized search tree exist and is referenced by the internal pointer root

    // Postcondition: if the value x is not in the tree, a node containing x is insert as a new leaf of the search tree

    //

    void searchTree::insert( int x )

    {

    insert( root, x );

    }

    // full

    //

    // Purpose: Test if the binary search tree is a full tree

    //

    // Precondition: properly initialized search tree exist and is referenced by the internal pointer root

    // Postcondition: if tree is a full tree, return true otherwise return false

    //

    bool searchTree::full() const

    {

    //add code here

    }

    // print

    //

    // Purpose: to display the tree nodes inorder

    //

    // Precondition: the tree is properly initialized

    // Postcondition: none

    //

    //

    void searchTree:: print()

    {

    if ( root == NULL )

    cout << "Empty Tree" << endl;

    else

    {

    cout << "Tree Content (inorder traversal): ";

    inorder( root );

    cout << endl;

    }

    }

    // inorder (private member function supports print)

    //

    // Purpose: to display the tree nodes inorder

    //

    // Precondition: t is an initailized pointer to a tree node

    // Postcondition: none

    //

    //

    void searchTree::inorder( treeNode* t )

    {

    if ( t != NULL )

    {

    inorder( t->left );

    cout << t->data << " ";

    inorder( t->right );

    }

    }

    // destroy (private member function supports ~searchTree)

    //

    // Purpose: to release all memory allocated to a tree

    //

    // Precondition: t is an initialized pointer to the root of the entire tree

    // Postcondition: all tree nodes are deallocated

    //

    void searchTree::destroy( treeNode* t )

    {

    if ( t != NULL )

    {

    destroy( t->left );

    destroy( t->right );

    delete t;

    }

    }

    // copy (private member function supports searchTree copy constructor)

    //

    // Purpose: to produce a copy of a searchTree

    //

    // Precondition: root is an initialized pointer to the root of the entire tree

    // Postcondition: all tree nodes in tree reference by t are copied and returned as the value of the function

    //

    treeNode* searchTree::copy( treeNode* t )

    {

    if ( t == NULL )

    {

    return NULL;

    }

    else

    {

    treeNode* nt = new treeNode( t->data );

    nt->left = copy( t->left );

    nt->right = copy( t->right );

    return nt;

    }

    }

    // insert

    //

    // Purpose: insert a node containing x into the search tree, if it does not already exists

    //

    // Precondition: properly initialized search tree exist and is referenced by the pointer root

    // Postcondition: if the value x is not in the tree, a node containing x is insert as a new leaf of the search tree

    //

    void searchTree::insert( treeNode*& t, int x )

    {

    if ( t == NULL )

    t = new treeNode( x );

    else if ( t->data < x )

    insert( t->right, x );

    else if ( t->data > x )

    insert( t->left, x );

    }

    He is now demanding a function that checks if the tree is full. I know that a binary tree is full if every leaf node has the same depth and every non-leaf node (interior node) has two children. but I don't know how to turn that into a code! I'd highly appreciate if someone could gimme the code and a brief illustration on how he did it so I know what's going on

    In case you wonder, yes it's something for school

    Thanks in advance

    2 AnswersProgramming & Design9 years ago