Search Results

Search found 5202 results on 209 pages for 'char'.

Page 1/209 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • C++ difference between "char *" and "char * = new char[]"

    - by nashmaniac
    So, if I want to declare an array of characters I can go this way char a[2]; char * a ; char * a = new char[2]; Ignoring the first declaration, the other two use pointers. As far as I know the third declaration is stored in heap and is freed using the delete operator . does the second declaration also hold the array in heap ? Does it mean that if something is stored in heap and not freed can be used anywhere in a file like a variable with file linkage ? I tried both third and second declaration in one function and then using the variable in another but it didn't work, why ? Are there any other differences between the second and third declarations ?

    Read the article

  • C appending char to char*

    - by Ostap Hnatyuk
    So I'm trying to append a char to a char*. For example I have char *word = " "; I also have char ch = 'x'; I do append(word, ch); Using this method.. void append(char* s, char c) { int len = strlen(s); s[len] = c; s[len+1] = '\0'; } It gives me a segmentation fault, and I understand why I suppose. Because s[len] is out of bounds. How do I make it so it works? I need to clear the char* a lot as well, if I were to use something like char word[500]; How would I clear that once it has some characters appended to it? Would the strlen of it always be 500? Thanks in advance.

    Read the article

  • initializing char and char pointers

    - by ra170
    What's the difference between these: This one works: char* pEmpty = new char; *pEmpty = 'x'; However if I try doing: char* pEmpty = NULL; pEmpty = 'x'; // <---- doesn't work! and: char* pEmpty = "x"; // putting in double quotes works! why??

    Read the article

  • Const unsigned char* to char*

    - by BSchlinker
    So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data; I'm attempting to perform a simple conversion of data from one to the other (string - const unsigned char*) As a result, I have the following: strcpy((unencrypted_data_char),(unencrypted_data.c_str())); However, I'm receiving the error: error C2664: 'strcpy' : cannot convert parameter 1 from 'const unsigned char *' to 'char *' Any advise? I thought using reinterpret_cast would help, but it doesn't seem to make a difference.

    Read the article

  • how to use char* as char[]

    - by phunehehe
    Hello, I have a struck like this typedef struct bookStruct { char title[80]; char author[80]; } BookType; And I have two strings like this char *title = "A Book on C"; char *author = "A. Kelly"; Now I can't create a BookType like this BookType book = {title, author}; Can anyone tell me what is wrong? How can I do that?

    Read the article

  • char[] and char* compatibility?

    - by Aerovistae
    In essence, will this code work? And before you say "Run it and see!", I just realized my cygwin didn't come with gcc and it's currently 40 minutes away from completing reinstallation. That being said: char* words[1000]; for(int i = 0; i<1000; i++) words[i] = NULL; char buffer[ 1024 ]; //omit code that places "ADD splash\0" into the buffer if(strncmp (buffer, "ADD ", 4){ char* temp = buffer + 4; printf("Adding: %s", temp); int i = 0; while(words[i] != NULL) i++; words[i] = temp; } I'm mostly uncertain about the line char* temp = buffer + 4, and also whether I can assign words[i] in the manner that I am. Am I going to get type errors when I eventually try to compile this in 40 minutes? Also-- if this works, why don't I need to use malloc() on each element of words[]? Why can I say words[i] = temp, instead of needing to allocate memory for words[i] the length of temp?

    Read the article

  • C# assign char and char array to string?

    - by Bopha
    char character = 'c'; string str = null; str = character.ToString();//this is ok char[] arrayChar = { 'a', 'b', 'c', 'd' }; string str2 = null; str2 = string.Copy(arrayChar.ToString());//this is not ok str2 = arrayChar.ToString();//this is not ok. I'm trying to converting char array to string, but the last two attempts don't work. Other source I found and they have to create new string type, but I don't know why. Can someone give me little explaination, thanks.

    Read the article

  • Difference between static const char* and const char*.

    - by Will MacDonagh
    Could someone please explain the difference in how the 2 snippets of code are handled below? They definitely compile to different assembly code, but I'm trying to understand how the code might act differently. I understand that string literals are thrown into read only memory and are effectively static, but how does that differ from the explicit static below? struct Obj1 { void Foo() { const char* str( "hello" ); } }; and struct Obj2 { void Bar() { static const char* str( "hello" ); } };

    Read the article

  • build error with boost spirit grammar (boost 1.43 and g++ 4.4.1)

    - by lurscher
    I'm having issues getting a small spirit/qi grammar to compile. The build stack trace is fugly enought to not make any sense to me (despite some assertion_failed i could notice in there but that didn't brought much information) the input grammar header: inputGrammar.h #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/fusion/include/adapt_struct.hpp> #include <boost/variant/recursive_variant.hpp> #include <boost/foreach.hpp> #include <iostream> #include <fstream> #include <string> #include <vector> namespace sp = boost::spirit; namespace qi = boost::spirit::qi; using namespace boost::spirit::ascii; //using namespace boost::spirit::arg_names; namespace fusion = boost::fusion; namespace phoenix = boost::phoenix; using phoenix::at_c; using phoenix::push_back; template< typename Iterator , typename ExpressionAST > struct InputGrammar : qi::grammar<Iterator, ExpressionAST(), space_type> { InputGrammar() : InputGrammar::base_type( block ) { tag = sp::lexeme[+(alpha) [sp::_val += sp::_1]];//[+(char_ - '<') [_val += _1]]; block = sp::lit("block") [ at_c<0>(sp::_val) = sp::_1] >> "(" >> *instruction[ push_back( at_c<1>(sp::_val) , sp::_1 ) ] >> ")"; command = tag [ at_c<0>(sp::_val) = sp::_1] >> "(" >> *instruction [ push_back( at_c<1>(sp::_val) , sp::_1 )] >> ")"; instruction = ( command | tag ) [sp::_val = sp::_1]; } qi::rule< Iterator , std::string() , space_type > tag; qi::rule< Iterator , ExpressionAST() , space_type > block; qi::rule< Iterator , ExpressionAST() , space_type > function_def; qi::rule< Iterator , ExpressionAST() , space_type > command; qi::rule< Iterator , ExpressionAST() , space_type > instruction; }; the test build program: i seems the build fails at qi::phrase_parse, i am using boost 1.43 and g++ 4.4.1 #include <iostream> #include <string> #include <vector> using namespace std; //my grammar #include <InputGrammar.h> struct MockExpressionNode { std::string name; std::vector< MockExpressionNode > operands; typedef std::vector< MockExpressionNode >::iterator iterator; typedef std::vector< MockExpressionNode >::const_iterator const_iterator; iterator begin() { return operands.begin(); } const_iterator begin() const { return operands.begin(); } iterator end() { return operands.end(); } const_iterator end() const { return operands.end(); } bool is_leaf() const { return ( operands.begin() == operands.end() ); } }; BOOST_FUSION_ADAPT_STRUCT( MockExpressionNode, (std::string, name) (std::vector<MockExpressionNode>, operands) ) int const tabsize = 4; void tab(int indent) { for (int i = 0; i < indent; ++i) std::cout << ' '; } template< typename ExpressionNode > struct ExpressionNodePrinter { ExpressionNodePrinter(int indent = 0) : indent(indent) { } void operator()(ExpressionNode const& node) const { cout << " tag: " << node.name << endl; for (int i=0 ; i < node.operands.size() ; i++ ) { tab( indent ); cout << " arg "<<i<<": "; ExpressionNodePrinter(indent + 2)( node.operands[i]); cout << endl; } } int indent; }; int test() { MockExpressionNode root; InputGrammar< string::const_iterator , MockExpressionNode > g(); std::string litA = "litA"; std::string litB = "litB"; std::string litC = "litC"; std::string litD = "litD"; std::string litE = "litE"; std::string litF = "litF"; std::string source = litA+"( "+litB+" ,"+litC+" , "+ litD+" ( "+litE+", "+litF+" ) "+ " )"; string::const_iterator iter = source.begin(); string::const_iterator end = source.end(); bool r = qi::phrase_parse( iter , end , g , root , space ); ExpressionNodePrinter< MockExpressionNode > np; np( root ); }; int main() { test(); } finally, the build error is the following: /usr/bin/make -f nbproject/Makefile-linux_amd64_devel.mk SUBPROJECTS= .build-conf make[1]: se ingresa al directorio `/home/mineq/NetBeansProjects/InputParserTests' /usr/bin/make -f nbproject/Makefile-linux_amd64_devel.mk dist/linux_amd64_devel/GNU-Linux-x86/vpuinputparsertests make[2]: se ingresa al directorio `/home/mineq/NetBeansProjects/InputParserTests' mkdir -p build/linux_amd64_devel/GNU-Linux-x86 rm -f build/linux_amd64_devel/GNU-Linux-x86/tests_main.o.d g++ `llvm-config --cxxflags` `pkg-config --cflags unittest-cpp` `pkg-config --cflags boost-1.43` `pkg-config --cflags boost-coroutines` -c -g -I../InputParser -MMD -MP -MF build/linux_amd64_devel/GNU-Linux-x86/tests_main.o.d -o build/linux_amd64_devel/GNU-Linux-x86/tests_main.o tests_main.cpp from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/auto.hpp:16, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi.hpp:15, from /home/mineq/third_party/boost_1_43_0/boost/spirit/include/qi.hpp:16, from ../InputParser/InputGrammar.h:12, from tests_main.cpp:14: /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp: In function ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]’: In file included from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/detail/parse_auto.hpp:14, /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:125: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::spirit::ascii::space_type]’ tests_main.cpp:206: instantiated from here /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:99: error: no matching function for call to ‘assertion_failed(mpl_::failed************ (boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]::error_invalid_expression::************)(InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode> (*)()))’ /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:125: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::spirit::ascii::space_type]’ tests_main.cpp:206: instantiated from here /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:100: error: no matching function for call to ‘assertion_failed(mpl_::failed************ (boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]::error_invalid_expression::************)(MockExpressionNode))’ from /home/mineq/third_party/boost_1_43_0/boost/proto/proto.hpp:12, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/support/meta_compiler.hpp:17, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/meta_compiler.hpp:14, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/action/action.hpp:14, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/action.hpp:14, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi.hpp:14, from /home/mineq/third_party/boost_1_43_0/boost/spirit/include/qi.hpp:16, from ../InputParser/InputGrammar.h:12, from tests_main.cpp:14: /home/mineq/third_party/boost_1_43_0/boost/proto/detail/expr0.hpp: At global scope: /home/mineq/third_party/boost_1_43_0/boost/proto/proto_fwd.hpp: In instantiation of ‘boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>()>, 0l>’: In file included from /home/mineq/third_party/boost_1_43_0/boost/proto/core.hpp:13, /home/mineq/third_party/boost_1_43_0/boost/utility/enable_if.hpp:59: instantiated from ‘boost::disable_if<boost::proto::result_of::is_expr<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>()>, 0l>, void>, void>’ /home/mineq/third_party/boost_1_43_0/boost/spirit/home/support/meta_compiler.hpp:200: instantiated from ‘boost::spirit::result_of::compile<boost::spirit::qi::domain, InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), boost::fusion::unused_type, void>’ /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:107: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]’ /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:125: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::spirit::ascii::space_type]’ tests_main.cpp:206: instantiated from here /home/mineq/third_party/boost_1_43_0/boost/proto/detail/expr0.hpp:64: error: field ‘boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>()>, 0l>::child0’ invalidly declared function type from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/auto.hpp:16, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi.hpp:15, from /home/mineq/third_party/boost_1_43_0/boost/spirit/include/qi.hpp:16, from ../InputParser/InputGrammar.h:12, from tests_main.cpp:14: /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp: In function ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]’: In file included from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/detail/parse_auto.hpp:14, /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:125: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::spirit::ascii::space_type]’ tests_main.cpp:206: instantiated from here /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:107: error: request for member ‘parse’ in ‘boost::spirit::compile [with Domain = boost::spirit::qi::domain, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>()](((InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode> (&)())((InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode> (*)())expr)))’, which is of non-class type ‘InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>()’ from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/auto.hpp:15, from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi.hpp:15, from /home/mineq/third_party/boost_1_43_0/boost/spirit/include/qi.hpp:16, from ../InputParser/InputGrammar.h:12, from tests_main.cpp:14: /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/skip_over.hpp: In function ‘void boost::spirit::qi::skip_over(Iterator&, const Iterator&, const T&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, T = boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]::skipper_type]’: In file included from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/auto/auto.hpp:19, /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:112: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>]’ /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/parse.hpp:125: instantiated from ‘bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, Attr&) [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Expr = InputGrammar<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode>(), Skipper = MockExpressionNode, Attr = const boost::spirit::ascii::space_type]’ tests_main.cpp:206: instantiated from here /home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/skip_over.hpp:27: error: ‘const struct MockExpressionNode’ has no member named ‘parse’ make[2]: *** [build/linux_amd64_devel/GNU-Linux-x86/tests_main.o] Error 1 make[2]: se sale del directorio `/home/mineq/NetBeansProjects/InputParserTests' make[1]: *** [.build-conf] Error 2 make[1]: se sale del directorio `/home/mineq/NetBeansProjects/InputParserTests' make: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 1m 48s)

    Read the article

  • C#/.NET Little Wonders: Static Char Methods

    - by James Michael Hare
    Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Often times in our code we deal with the bigger classes and types in the BCL, and occasionally forgot that there are some nice methods on the primitive types as well.  Today we will discuss some of the handy static methods that exist on the char (the C# alias of System.Char) type. The Background I was examining a piece of code this week where I saw the following: 1: // need to get the 5th (offset 4) character in upper case 2: var type = symbol.Substring(4, 1).ToUpper(); 3:  4: // test to see if the type is P 5: if (type == "P") 6: { 7: // ... do something with P type... 8: } Is there really any error in this code?  No, but it still struck me wrong because it is allocating two very short-lived throw-away strings, just to store and manipulate a single char: The call to Substring() generates a new string of length 1 The call to ToUpper() generates a new upper-case version of the string from Step 1. In my mind this is similar to using ToUpper() to do a case-insensitive compare: it isn’t wrong, it’s just much heavier than it needs to be (for more info on case-insensitive compares, see #2 in 5 More Little Wonders). One of my favorite books is the C++ Coding Standards: 101 Rules, Guidelines, and Best Practices by Sutter and Alexandrescu.  True, it’s about C++ standards, but there’s also some great general programming advice in there, including two rules I love:         8. Don’t Optimize Prematurely         9. Don’t Pessimize Prematurely We all know what #8 means: don’t optimize when there is no immediate need, especially at the expense of readability and maintainability.  I firmly believe this and in the axiom: it’s easier to make correct code fast than to make fast code correct.  Optimizing code to the point that it becomes difficult to maintain often gains little and often gives you little bang for the buck. But what about #9?  Well, for that they state: “All other things being equal, notably code complexity and readability, certain efficient design patterns and coding idioms should just flow naturally from your fingertips and are no harder to write then the pessimized alternatives. This is not premature optimization; it is avoiding gratuitous pessimization.” Or, if I may paraphrase: “where it doesn’t increase the code complexity and readability, prefer the more efficient option”. The example code above was one of those times I feel where we are violating a tacit C# coding idiom: avoid creating unnecessary temporary strings.  The code creates temporary strings to hold one char, which is just unnecessary.  I think the original coder thought he had to do this because ToUpper() is an instance method on string but not on char.  What he didn’t know, however, is that ToUpper() does exist on char, it’s just a static method instead (though you could write an extension method to make it look instance-ish). This leads me (in a long-winded way) to my Little Wonders for the day… Static Methods of System.Char So let’s look at some of these handy, and often overlooked, static methods on the char type: IsDigit(), IsLetter(), IsLetterOrDigit(), IsPunctuation(), IsWhiteSpace() Methods to tell you whether a char (or position in a string) belongs to a category of characters. IsLower(), IsUpper() Methods that check if a char (or position in a string) is lower or upper case ToLower(), ToUpper() Methods that convert a single char to the lower or upper equivalent. For example, if you wanted to see if a string contained any lower case characters, you could do the following: 1: if (symbol.Any(c => char.IsLower(c))) 2: { 3: // ... 4: } Which, incidentally, we could use a method group to shorten the expression to: 1: if (symbol.Any(char.IsLower)) 2: { 3: // ... 4: } Or, if you wanted to verify that all of the characters in a string are digits: 1: if (symbol.All(char.IsDigit)) 2: { 3: // ... 4: } Also, for the IsXxx() methods, there are overloads that take either a char, or a string and an index, this means that these two calls are logically identical: 1: // check given a character 2: if (char.IsUpper(symbol[0])) { ... } 3:  4: // check given a string and index 5: if (char.IsUpper(symbol, 0)) { ... } Obviously, if you just have a char, then you’d just use the first form.  But if you have a string you can use either form equally well. As a side note, care should be taken when examining all the available static methods on the System.Char type, as some seem to be redundant but actually have very different purposes.  For example, there are IsDigit() and IsNumeric() methods, which sound the same on the surface, but give you different results. IsDigit() returns true if it is a base-10 digit character (‘0’, ‘1’, … ‘9’) where IsNumeric() returns true if it’s any numeric character including the characters for ½, ¼, etc. Summary To come full circle back to our opening example, I would have preferred the code be written like this: 1: // grab 5th char and take upper case version of it 2: var type = char.ToUpper(symbol[4]); 3:  4: if (type == 'P') 5: { 6: // ... do something with P type... 7: } Not only is it just as readable (if not more so), but it performs over 3x faster on my machine:    1,000,000 iterations of char method took: 30 ms, 0.000050 ms/item.    1,000,000 iterations of string method took: 101 ms, 0.000101 ms/item. It’s not only immediately faster because we don’t allocate temporary strings, but as an added bonus there less garbage to collect later as well.  To me this qualifies as a case where we are using a common C# performance idiom (don’t create unnecessary temporary strings) to make our code better. Technorati Tags: C#,CSharp,.NET,Little Wonders,char,string

    Read the article

  • std::cin >> *aa results in a bus error

    - by Koning Baard XIV
    I have this a class called PPString: PPString.h #ifndef __CPP_PPString #define __CPP_PPString #include "PPObject.h" class PPString : public PPObject { char *stringValue[]; public: char *pointerToCharString(); void setCharString(char *charString[]); void setCharString(const char charString[]); }; #endif PPString.cpp #include "PPString.h" char *PPString::pointerToCharString() { return *stringValue; } void PPString::setCharString(char *charString[]) { *stringValue = *charString; } void PPString::setCharString(const char charString[]) { *stringValue = (char *)charString; } I'm trying to set the stringValue using std::cin: main.cpp PPString myString; myString.setCharString("LOLZ"); std::cout << myString.pointerToCharString() << std::endl; char *aa[1000]; std::cin >> *aa; myString.setCharString(aa); std::cout << myString.pointerToCharString() << std::endl; The first one, which uses a const char works, but the second one, with a char doesn't, and I get this output: copy and paste from STDOUT LOLZ im entering a string now... Bus error where the second line is what I entered, followed by pressing the return key. Can anyone help me fixing this? Thanks...

    Read the article

  • I can't get that `bus error` to stop sucking.

    - by Koning Baard XIV
    I have this a class called PPString: PPString.h #ifndef __CPP_PPString #define __CPP_PPString #include "PPObject.h" class PPString : public PPObject { char *stringValue[]; public: char *pointerToCharString(); void setCharString(char *charString[]); void setCharString(const char charString[]); }; #endif PPString.cpp #include "PPString.h" char *PPString::pointerToCharString() { return *stringValue; } void PPString::setCharString(char *charString[]) { *stringValue = *charString; } void PPString::setCharString(const char charString[]) { *stringValue = (char *)charString; } I'm trying to set the stringValue using std::cin: main.cpp PPString myString; myString.setCharString("LOLZ"); std::cout << myString.pointerToCharString() << std::endl; char *aa[1000]; std::cin >> *aa; myString.setCharString(aa); std::cout << myString.pointerToCharString() << std::endl; The first one, which uses a const char works, but the second one, with a char doesn't, and I get this output: copy and paste from STDOUT LOLZ im entering a string now... Bus error where the second line is what I entered, followed by pressing the return key. Can anyone help me fixing this? Thanks...

    Read the article

  • berkeley DB: can't compile c++ codes

    - by Brian
    When I compiled the sample codes of C++, I got following info: c++ excxx_example_database_read.cpp -o dbApp -I /usr/local/BerkeleyDB.5.0/include/ Undefined symbols: "Dbt::Dbt(void*, unsigned int)", referenced from: show_vendor(MyDb&, char const*)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o "Dbc::get(Dbt*, Dbt*, unsigned int)", referenced from: show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o "Dbc::close()", referenced from: show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o "Dbt::~Dbt()", referenced from: show_vendor(MyDb&, char const*)in ccnaWItX.o show_vendor(MyDb&, char const*)in ccnaWItX.o show_vendor(MyDb&, char const*)in ccnaWItX.o show_vendor(MyDb&, char const*)in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o "Db::~Db()", referenced from: MyDb::~MyDb() in ccnaWItX.o MyDb::~MyDb() in ccnaWItX.o "typeinfo for DbException", referenced from: GCC_except_table3 in ccnaWItX.o GCC_except_table4 in ccnaWItX.o GCC_except_table5 in ccnaWItX.o GCC_except_table6 in ccnaWItX.o __ZTI11DbException$non_lazy_ptr in ccnaWItX.o "DbException::~DbException()", referenced from: __ZN11DbExceptionD1Ev$non_lazy_ptr in ccnaWItX.o "MyDb::close()", referenced from: MyDb::~MyDb() in ccnaWItX.o "MyDb::MyDb(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool)", referenced from: _main in ccnaWItX.o _main in ccnaWItX.o _main in ccnaWItX.o "Dbt::Dbt()", referenced from: show_vendor(MyDb&, char const*)in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o "DbException::get_errno() const", referenced from: show_vendor(MyDb&, char const*)in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o _main in ccnaWItX.o "DbException::DbException(DbException const&)", referenced from: show_vendor(MyDb&, char const*)in ccnaWItX.o show_all_records(MyDb&, MyDb&) in ccnaWItX.o show_item(MyDb&, MyDb&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)in ccnaWItX.o ld: symbol(s) not found collect2: ld returned 1 exit status I have no idea what is the problem. Please help!

    Read the article

  • scanf("%d", char*) - char-as-int format string?

    - by SF.
    What is the format string modifier for char-as-number? I want to read in a number never exceeding 255 (actually much less) into an unsigned char type variable using sscanf. Using the typical char source[] = "x32"; char separator; unsigned char dest; int len; len = sscanf(source,"%c%d",&separator,&dest); // validate and proceed... I'm getting the expected warning: argument 4 of sscanf is type char*, int* expected. As I understand the specs, there is no modifier for char (like %sd for short, or %lld for 64-bit long) is it dangerous? (will overflow just overflow (roll-over) the variable or will it write outside the allocated space?) is there a prettier way to achieve that than allocating a temporary int variable? ...or would you suggest an entirely different approach altogether?

    Read the article

  • Python to C/C++ const char question

    - by tsukemonoki
    I am extending Python with some C++ code. One of the functions I'm using has the following signature: int PyArg_ParseTupleAndKeywords(PyObject *arg, PyObject *kwdict, char *format, char **kwlist, ...); (link: http://docs.python.org/release/1.5.2p2/ext/parseTupleAndKeywords.html) The parameter of interest is kwlist. In the link above, examples on how to use this function are given. In the examples, kwlist looks like: static char *kwlist[] = {"voltage", "state", "action", "type", NULL}; When I compile this using g++, I get the warning: warning: deprecated conversion from string constant to ‘char*’ So, I can change the static char* to a static const char*. Unfortunately, I can't change the Python code. So with this change, I get a different compilation error (can't convert char** to const char**). Based on what I've read here, I can turn on compiler flags to ignore the warning or I can cast each of the constant strings in the definition of kwlist to char *. Currently, I'm doing the latter. What are other solutions? Sorry if this question has been asked before. I'm new.

    Read the article

  • Is it appropriate to set a value to a "const char *" in the header file

    - by sud
    I have seen people using 2 methods to declare and define char * Medhod-1: The header file has the below const char* COUNTRY_NAME_USA = "USA"; Medhod-2: The header file has the below declaration const char* COUNTRY_NAME_USA; The cpp file has the below defintion : const char* COUNTRY_NAME_USA = "USA"; Is method-2 wrong in some way ? What is the difference between the two ? I understand the difference between "const char * const var" , and "const char * var". If in the above methods if a "const char * const var" is declared and defined in the header as in method 1 will it make sense ?

    Read the article

  • Returning char* in function

    - by Devel
    I have function: char *zap(char *ar) { char pie[100] = "INSERT INTO test (nazwa, liczba) VALUES ('nowy wpis', '"; char dru[] = "' )"; strcat(pie, ar); strcat(pie, dru); return pie; } and in main there is: printf("%s", zap( argv[1] ) ); When compiling I get the warning: test.c: In function ‘zap’: test.c:17: warning: function returns address of local variable How should I return char* propertly?

    Read the article

  • casting char* to char**

    - by blue_whale
    I am having a tough time understanding the following piece of code: int stride = 512; int max_len = 1024 * stride; char *addr = (char *)malloc(max_len); for (int i=stride; i<max_len; i += stride) *(char **)&addr[i-stride] = (char*)&addr[i]; *(char **)&addr[i-stride] = (char*)&addr[0]; Looking at the code it seems this is trying to create some kind of circular link list. But I have no clue what those casts are actually doing.

    Read the article

  • Specializing function template for both std::string and char*

    - by sad_man
    As the title says I want to specialize a function template for both string and char pointer, so far I did this but I can not figure out passing the string parameters by reference. #include <iostream> #include <string> template<typename T> void xxx(T param) { std::cout << "General : "<< sizeof(T) << std::endl; } template<> void xxx<char*>(char* param) { std::cout << "Char ptr: "<< strlen(param) << std::endl; } template<> void xxx<const char* >(const char* param) { std::cout << "Const Char ptr : "<< strlen(param)<< std::endl; } template<> void xxx<const std::string & >(const std::string & param) { std::cout << "Const String : "<< param.size()<< std::endl; } template<> void xxx<std::string >(std::string param) { std::cout << "String : "<< param.size()<< std::endl; } int main() { xxx("word"); std::string aword("word"); xxx(aword); std::string const cword("const word"); xxx(cword); } Also template<> void xxx<const std::string & >(const std::string & param) thing just does not working. If I rearranged the opriginal template to accept parameters as T& then the char * is required to be char * & which is not good for static text in code. Please help !

    Read the article

  • Segmentation fault on writing char to char* address

    - by Lukas Dojcak
    hi guys, i've got problem with my little C program. Maybe you could help me. char* shiftujVzorku(char* text, char* pattern, int offset){ char* pom = text; int size = 0; int index = 0; while(*(text + size) != '\0'){ size++; } while(*(pom + index) != '\0'){ if(overVzorku(pom + index, pattern)){ while(*pattern != '\0'){ //vyment *pom s *pom + offset if(pom + index + offset < text + size){ char x = *(pom + index + offset); char y = *(pom + index); int adresa = *(pom + index + offset); *(pom + index + offset) = y; <<<<<< SEGMENTATION FAULT *(pom + index) = x; //*pom = *pom - *(pom + offset); //*(pom + offset) = *(pom + offset) + *pom; //*pom = *(pom + offset) - *pom; } else{ *pom = *pom - *(pom + offset - size); *(pom + offset - size) = *(pom + offset - size) + *pom; *pom = *(pom + offset - size) - *pom; } pattern++; } break; } index++; } return text; } Isn't important what's the programm doing. Mayby there's lot of bugs. But, why do I get SEGMENTATION FAULT (for destination see code) at this line? I'm, trying to write some char value to memory space, with help of address "pom + offset + index". Thanks for everything helpful. :)

    Read the article

  • pointer, malloc and char in C

    - by user2534078
    im trying to copy a const char array to some place in the memory and point to it . lets say im defining this var under the main prog : char *p = NULL; and sending it to a function with a string : myFunc(&p, "Hello"); now i want that at the end of this function the pointer will point to the letter H but if i puts() it, it will print Hello . here is what i tried to do : void myFunc(char** ptr , const char strng[] ) { *ptr=(char *) malloc(sizeof(strng)); char * tmp=*ptr; int i=0; while (1) { *ptr[i]=strng[i]; if (strng[i]=='\0') break; i++; } *ptr=tmp; } i know its a rubbish now, but i would like to understand how to do it right, my idea was to allocate the needed memory, copy a char and move forward with the pointer, etc.. also i tried to make the ptr argument byreferenec (like &ptr) but with no success due to a problem with the lvalue and rvalue . the only thing is changeable for me is the function, and i would like not to use strings, but chars as this is and exercise . thanks for any help in advance.

    Read the article

  • Const unsigned char* to char8

    - by BSchlinker
    So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data; I'm attempting to perform a simple conversion of data from one to the other (string - const unsigned char*) As a result, I have the following: strcpy((unencrypted_data_char),(unencrypted_data.c_str())); However, I'm receiving the error: error C2664: 'strcpy' : cannot convert parameter 1 from 'const unsigned char *' to 'char *' Any advise? I thought using reinterpret_cast would help, but it doesn't seem to make a difference.

    Read the article

  • Typcast a null pointer to char*

    - by user326253
    Suppose I have a char* elem that is supposed to hold a char*, s.t. elem[0] = char*, elem[1...m]= more chars. Is there a way I can put a null ptr within char* elem? When I try to set elem = NULL, it gives me a type error because NULL is an int. Any help would be greatly appreciated!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >