Search Results

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

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

  • how to copy char * into a string and visa versa

    - by user295030
    If i pass a char * into a function. I want to then take that char * convert it to a std::string and once I get my result convert it back to char * from a std::string to show the result. I don't know how to do this for conversion ( I am not talking const char * but just char *) I am not sure how to manipulate the value of the pointer I send in. so steps i need to do take in a char * convert it into a string. take the result of that string and put it back in the form of a char * return the result such that the value should be available outside the function and not get destroyed. If possible can i see how it could be done via reference vs a pointer (whose address I pass in by value however I can still modify the value that pointer is pointing to. so even though the copy of the pointer address in the function gets destroyed i still see the changed value outside. thanks!

    Read the article

  • C++ struct containing unsigned char and int bug

    - by powerfear
    Ok i have a struct in my C++ program that is like this: struct thestruct { unsigned char var1; unsigned char var2; unsigned char var3[2]; unsigned char var4; unsigned char var5[8]; int var6; unsigned char var7[4]; }; When i use this struct, 3 random bytes get added before the "var6", if i delete "var5" it's still before "var6" so i know it's always before the "var6". But if i remove the "var6" then the 3 extra bytes are gone. If i only use a struct with a int in it, there is no extra bytes. So there seem to be a conflict between the unsigned char and the int, how can i fix that?

    Read the article

  • how to copy char * into a string and vice-versa

    - by user295030
    If i pass a char * into a function. I want to then take that char * convert it to a std::string and once I get my result convert it back to char * from a std::string to show the result. I don't know how to do this for conversion ( I am not talking const char * but just char *) I am not sure how to manipulate the value of the pointer I send in. so steps i need to do take in a char * convert it into a string. take the result of that string and put it back in the form of a char * return the result such that the value should be available outside the function and not get destroyed. If possible can i see how it could be done via reference vs a pointer (whose address I pass in by value however I can still modify the value that pointer is pointing to. so even though the copy of the pointer address in the function gets destroyed i still see the changed value outside. thanks!

    Read the article

  • C - memset segfault for statically allocated char array

    - by user1327031
    I get a segfault when trying to memset an array of chars that was allocated statically, but not for an array of the same length that was allocated using malloc. variable definitions: //static char inBuff[IN_BUFF_LEN]; //dynamic char * inBuffD; function call: //static, cast used because char** != char (*) [n] serverInit(portNum, (char**) &inBuff, &serv_addr, &sockfd) //dynamic serverInit(portNum, &inBuffD, &serv_addr, &sockfd) use within the function: memset(*inBuffAdr, 0, IN_BUFF_LEN); I suspect that my problem is in the difference of the function calls, or to be more precise, my incomplete understanding of the "char** != char (*) [n]" situation. But I have been banging at this for too long and can't see the forest from the trees so any hints and advice would be very appreciated.

    Read the article

  • C: Incompatible types?

    - by Airjoe
    #include <stdlib.h> #include <stdio.h> struct foo{ int id; char *bar; char *baz[6]; }; int main(int argc, char **argv){ struct foo f; f.id=1; char *qux[6]; f.bar=argv[0]; f.baz=qux; // Marked line return 1; } This is just some test code so ignore that qux doesn't actually have anything useful in it. I'm getting an error on the marked line, incompatible types when assigning to type ‘char *[6]’ from type ‘char **’ but both of the variables are defined as char *[6] in the code. Any insight?

    Read the article

  • How to 'convert' char to function in C

    - by Tim van Elsloo
    Hi, void someFunction() { char *function = "anotherFunction"; const char *params[] = {"aVal","bVal","cVal"}; // How can I call the *function with the *params? } void anotherFunction(char *aKey, char *bKey, char *cKey) { // Do something with *aKey, *bKey and *cKey; } Does someone know how to call the *function with the *params? Thanks in advance, Tim

    Read the article

  • storing characters in char data type C language

    - by iSight
    Hi, I can store string of few length in char data type. But when it exceeds its capacity what can be the alternative way to store string. I am using char data type. void setString(char* inPoints) { if (strcmp(mPoints, inPoints)!= ZERO) { if (mPoints) { free(mPoints); } mPoints = (char*)malloc((strlen(inPoints) + 1) * sizeof(char)); strcpy(mPoints, inPoints); } }

    Read the article

  • Connecting std::basic_ofstream<unsigned char> to a FIFO. bad_cast exceptions

    - by Mike B
    Using gcc 4.4.3 on Linux 2.6.32, I get bad_cast exceptions when connecting std::basic_ofstream to a FIFO. Stepping though the debugger, I can see that the error is generated at various places in the standard library because the _M_codecvt member of the stream or filebuf object is NULL. Exactly where it happens depends on the order of operations, but it appears to be the same cause in each. So am I doing something fundamentally stupid here? ofstream and ifstream work fine. Is there some reason that you shouldn't attach a stream of anything besides char to a FIFO? Thanks in advance.

    Read the article

  • How to add characters to reach the maximum size of a char[].

    - by Bon_chan
    Hi folks, I have the following part of code : for(int i=0;i<n;i++) { printf("Student %d\n",i+1); printf("Enter name : "); scanf("%s",&(student+i)->name); fflush(stdin); lengthName = strlen((student+i)->name); while(lengthName !='\0') { }} when the length is shorter than 10, it will add hyphens until reaching the maximum size. Ex : John = 6 hyphens will be added I know how to do it in csharp but can't figure it out in c. Could some of you give me some lights please? PS : Oh yes the variable name is char name[10+1] and it a part of the structure called student.

    Read the article

  • EVP_PKEY from char buffer in x509 (PKCS7)

    - by sid
    Hi All, I have a DER certificate from which I am retrieving the Public key in unsigned char buffer as following, is it the right way of getting? pStoredPublicKey = X509_get_pubkey(x509); if(pStoredPublicKey == NULL) { printf(": publicKey is NULL\n"); } if(pStoredPublicKey->type == EVP_PKEY_RSA) { RSA *x = pStoredPublicKey->pkey.rsa; bn = x->n; } else if(pStoredPublicKey->type == EVP_PKEY_DSA) { } else if(pStoredPublicKey->type == EVP_PKEY_EC) { } else { printf(" : Unkown publicKey\n"); } //extracts the bytes from public key & convert into unsigned char buffer buf_len = (size_t) BN_num_bytes (bn); key = (unsigned char *)malloc (buf_len); n = BN_bn2bin (bn, (unsigned char *) key); for (i = 0; i < n; i++) { printf("%02x\n", (unsigned char) key[i]); } keyLen = EVP_PKEY_size(pStoredPublicKey); EVP_PKEY_free(pStoredPublicKey); And, With this unsigned char buffer, How do I get back the EVP_PKEY for RSA? OR Can I use following ???, EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, long length); int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);

    Read the article

  • trie reg exp parse step over char and continue

    - by forest.peterson
    Setup: 1) a string trie database formed from linked nodes and a vector array linking to the next node terminating in a leaf, 2) a recursive regular expression function that if A) char '*' continues down all paths until string length limit is reached, then continues down remaining string paths if valid, and B) char '?' continues down all paths for 1 char and then continues down remaining string paths if valid. 3) after reg expression the candidate strings are measured for edit distance against the 'try' string. Problem: the reg expression works fine for adding chars or swapping ? for a char but if the remaining string has an error then there is not a valid path to a terminating leaf; making the matching function redundant. I tried adding a 'step-over' ? char if the end of the node vector was reached and then followed every path of that node - allowing this step-over only once; resulted in a memory exception; I cannot find logically why it is accessing the vector out of range - bactracking? Questions: 1) how can the regular expression step over an invalid char and continue with the path? 2) why is swapping the 'sticking' char for '?' resulting in an overflow? Function: void Ontology::matchRegExpHelper(nodeT *w, string inWild, Set<string> &matchSet, string out, int level, int pos, int stepover) { if (inWild=="") { matchSet.add(out); } else { if (w->alpha.size() == pos) { int testLength = out.length() + inWild.length(); if (stepover == 0 && matchSet.size() == 0 && out.length() > 8 && testLength == tokenLength) {//candidate generator inWild[0] = '?'; matchRegExpHelper(w, inWild, matchSet, out, level, 0, stepover+1); } else return; //giveup on this path } if (inWild[0] == '?' || (inWild[0] == '*' && (out.length() + inWild.length() ) == level ) ) { //wild matchRegExpHelper(w->alpha[pos].next, inWild.substr(1), matchSet, out+w->alpha[pos].letter, level, 0, stepover);//follow path -> if ontology is full, treat '*' like a '?' } else if (inWild[0] == '*') matchRegExpHelper(w->alpha[pos].next, '*'+inWild.substr(1), matchSet, out+w->alpha[pos].letter, level, 0, stepover); //keep adding chars if (inWild[0] == w->alpha[pos].letter) //follow self matchRegExpHelper(w->alpha[pos].next, inWild.substr(1), matchSet, out+w->alpha[pos].letter, level, 0, stepover); //follow char matchRegExpHelper(w, inWild, matchSet, out, level, pos+1, stepover);//check next path } } Error Message: +str "Attempt to access index 1 in a vector of size 1." std::basic_string<char,std::char_traits<char>,std::allocator<char> > +err {msg="Attempt to access index 1 in a vector of size 1." } ErrorException Note: this function works fine for hundreds of test strings with '*' wilds if the extra stepover gate is not used Semi-Solved: I place a pos < w->alpha.size() condition on each path that calls w->alpha[pos]... - this prevented the backtrack calls from attempting to access the vector with an out of bounds index value. Still have other issues to work out - it loops infinitely adding the ? and backtracking to remove it, then repeat. But, moving forward now. Revised question: why during backtracking is the position index accumulating and/or not deincrementing - so at somepoint it calls w->alpha[pos]... with an invalid position that is either remaining from the next node or somehow incremented pos+1 when passing upward?

    Read the article

  • C++: Trouble with templates (C2064)

    - by Rosarch
    I'm having compiler errors, and I'm not sure why. What am I doing wrong here: Hangman.cpp: set<char> Hangman::incorrectGuesses() { // Hangman line 103 return Utils::findAll_if<char>(guesses.begin(), guesses.end(), &Hangman::isIncorrectGuess); } bool Hangman::isIncorrectGuess(char c) { return correctAnswer.find(c) == string::npos; } Utils.h: namespace Utils { void PrintLine(const string& line, int tabLevel = 0); string getTabs(int tabLevel); template<class result_t, class Predicate> std::set<result_t> findAll_if(typename std::set<result_t>::iterator begin, typename std::set<result_t>::iterator end, Predicate pred) { std::set<result_t> result; // utils line 16 return detail::findAll_if_rec<result_t>(begin, end, pred, result); } } namespace detail { template<class result_t, class Predicate> std::set<result_t> findAll_if_rec(typename std::set<result_t>::iterator begin, typename std::set<result_t>::iterator end, Predicate pred, std::set<result_t> result) { // utils line 25 typename std::set<result_t>::iterator nextResultElem = find_if(begin, end, pred); if (nextResultElem == end) { return result; } result.insert(*nextResultElem); return findAll_if_rec(++nextResultElem, end, pred, result); } } This produces the following compiler errors: algorithm(83): error C2064: term does not evaluate to a function taking 1 arguments algorithm(95) : see reference to function template instantiation '_InIt std::_Find_if<std::_Tree_unchecked_const_iterator<_Mytree>,_Pr>(_InIt,_InIt,_Pr)' being compiled 1> with 1> [ 1> _InIt=std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>>, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> _Pr=bool (__thiscall Hangman::* )(char) 1> ] utils.h(25) : see reference to function template instantiation '_InIt std::find_if<std::_Tree_const_iterator<_Mytree>,Predicate>(_InIt,_InIt,_Pr)' being compiled 1> with 1> [ 1> _InIt=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>>, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> Predicate=bool (__thiscall Hangman::* )(char), 1> _Pr=bool (__thiscall Hangman::* )(char) 1> ] utils.h(16) : see reference to function template instantiation 'std::set<_Kty> detail::findAll_if_rec<result_t,Predicate>(std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>,Predicate,std::set<_Kty>)' being compiled 1> with 1> [ 1> _Kty=char, 1> result_t=char, 1> Predicate=bool (__thiscall Hangman::* )(char), 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>> 1> ] hangman.cpp(103) : see reference to function template instantiation 'std::set<_Kty> Utils::findAll_if<char,bool(__thiscall Hangman::* )(char)>(std::_Tree_const_iterator<_Mytree>,std::_Tree_const_iterator<_Mytree>,Predicate)' being compiled 1> with 1> [ 1> _Kty=char, 1> _Mytree=std::_Tree_val<std::_Tset_traits<char,std::less<char>,std::allocator<char>,false>>, 1> Predicate=bool (__thiscall Hangman::* )(char) 1> ]

    Read the article

  • How to test whether a char is NOT in a string? (java, junit)

    - by JB
    As title says, im having trouble with my junit tests passing for checking if a character is not in a string and how to check if an empty string doesnt have a character. here is the method i have: public static boolean isThere(String s, char value){ for(int x = 0; x <= s.length(); x++){ if(s.charAt(x) == value){ return true; } else if(s.length() == 0){ return false; } } return false; And here is the junit test: public void testIsThere() { { String sVal = "Jeff George"; boolean hasA = StringMethods.isThere(sVal,'e'); assertTrue(hasA); boolean hasE = StringMethods.isThere(sVal, 'o'); assertTrue(hasE); boolean notIn = StringMethods.isThere(sVal,'b'); assertTrue(notIn); } { String sVal = ""; boolean nothingIn = StringMethods.isThere(sVal,'a'); assertFalse(nothingIn); boolean notIn = StringMethods.isThere(sVal,'b'); assertFalse(notIn); } } Thank you very much, appreciated

    Read the article

  • Marshalling the value of a char* ANSI string DLL API parameter into a C# string

    - by Brian Biales
    For those who do not mix .NET C# code with legacy DLL's that use char* pointers on a regular basis, the process to convert the strings one way or the other is non-obvious. This is not a comprehensive article on the topic at all, but rather an example of something that took me some time to go find, maybe it will save someone else the time. I am utilizing a third party too that uses a call back function to inform my application of its progress.  This callback includes a pointer that under some circumstances is a pointer to an ANSI character string.  I just need to marshal it into a C# string variable.  Seems pretty simple, yes?  Well, it is, (as are most things, once you know how to do them). The parameter of my callback function is of type IntPtr, which implies it is an integer representation of a pointer.  If I know the pointer is pointing to a simple ANSI string, here is a simple static method to copy it to a C# string: private static string GetStringFromCharStar(IntPtr ptr) {     return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr); } The System.Runtime.InteropServices is where to look any time you are mixing legacy unmanaged code with your .NET application.

    Read the article

  • Return a pointer to a char array in C

    - by snitko
    I've seen a lot of questions on that on StackOverflow, but reading the answers did not clear that up for me, probably because I'm a total newbie in C programming. Here's the code: #include <stdio.h> char* squeeze(char s[], char c); main() { printf("%s", squeeze("hello", 'o')); } char* squeeze(char s[], char c) { int i, j; for(i = j = 0; s[i] != '\0'; i++) if(s[i] != c) s[j++] = s[i]; s[j] = '\0'; return s; } It compiles and I get segmentation fault when I run it. I've read this faq about about returning arrays and tried the 'static' technique that is suggested there, but still could not get the program working. Could anyone point out exactly what's wrong with it and what should I be paying attention in the future?

    Read the article

  • Array of strings and char ** environ variable.

    - by Naruto Uzumaki
    Hello! I want to know how an array of strings is declared? What I do is I declare an array of pointers of pointers to strings. Eg. char *array[]= {"string1","string2","string3"}; I was reading about modifying environment variables in Linux and stumbled upon the pointer char **environ ( http://www.cs.bham.ac.uk/resources/courses/2005/17423/doc/libc/Environment-Access.html#Environment-Access ). char **environ is declared as an array of strings. I think it should be a pointer to a pointer. For eg. char *array[]= {"string1","string2","string3"}; environ = array; Am I doing something wrong? I also read somewhere that char *argv[] = char **argv. How is it possible?

    Read the article

  • C++ error - returning a char array

    - by Yosy
    Consider the following code: char CeaserCrypt(char str[256],int key) { char encrypted[256],encryptedChar; int currentAsci; encrypted[0] = '\0'; for(int i = 0; i < strlen(str); i++) { currentAsci = (int)str[i]; encryptedChar = (char)(currentAsci+key); encrypted[i] = encryptedChar; } return encrypted; } Visual Studio 2010 gives an error because the function returns an array. What should I do? My friend told me to change the signature to void CeaserCrypt(char str[256], char encrypted[256], int key). But I don't think that is correct. How can I get rid of the compile error?

    Read the article

  • libstdc++ - compiling failing because of tr1/regex

    - by Radek Šimko
    I have these packages installed on my OpenSUSE 11.3: i | libstdc++45 | Standard shared library for C++ | package i | libstdc++45-devel | Contains files and libraries for development | package But when i'm trying to compile this C++ code: #include <stdio.h> #include <tr1/regex> using namespace std; int main() { int test[2]; const tr1::regex pattern(".*"); test[0] = 1; if (tr1::regex_match("anything", pattern) == false) { printf("Pattern does not match.\n"); } return 0; } using g++ -pedantic -g -O1 -o ./main.o ./main.cpp It outputs this errors: ./main.cpp: In function ‘int main()’: ./main.cpp:13:43: error: ‘printf’ was not declared in this scope radek@mypc:~> nano main.cpp radek@mypc:~> g++ -pedantic -g -O1 -o ./main.o ./main.cpp /tmp/cc0g3GUE.o: In function `basic_regex': /usr/include/c++/4.5/tr1_impl/regex:771: undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()' /tmp/cc0g3GUE.o: In function `bool std::tr1::regex_match<char const*, char, std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)': /usr/include/c++/4.5/tr1_impl/regex:2144: undefined reference to `bool std::tr1::regex_match<char const*, std::allocator<std::tr1::sub_match<char const*> >, char, std::tr1::regex_traits<char> >(char const*, char const*, std::tr1::match_results<char const*, std::allocator<std::tr1::sub_match<char const*> > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11u>)' collect2: ld returned 1 exit status What packages should i (un)install to make the code work on my PC?

    Read the article

  • question/problem regarding assigning an array of char *

    - by Fantastic Fourier
    Hi I'm working with C and I have a question about assigning pointers. struct foo { int _bar; char * _car[MAXINT]; // this is meant to be an array of char * so that it can hold pointers to names of cars } int foofunc (void * arg) { int bar; char * car[MAXINT]; struct foo thing = (struct foo *) arg; bar = arg->_bar; // this works fine car = arg->_car; // this gives compiler errors of incompatible types in assignment } car and _car have same declaration so why am I getting an error about incompatible types? My guess is that it has something to do with them being pointers (because they are pointers to arrays of char *, right?) but I don't see why that is a problem. when i declared char * car; instead of char * car[MAXINT]; it compiles fine. but I don't see how that would be useful to me later when I need to access certain info using index, it would be very annoying to access that info later. in fact, I'm not even sure if I am going about the right way, maybe there is a better way to store a bunch of strings instead of using array of char *?

    Read the article

  • Memory Management with returning char* function

    - by RageD
    Hello all, Today, without much thought, I wrote a simple function return to a char* based on a switch statement of given enum values. This, however, made me wonder how I could release that memory. What I did was something like this: char* func() { char* retval = new char; // Switch blah blah - will always return some value other than NULL since default: return retval; } I apologize if this is a naive question, but what is the best way to release the memory seeing as I cannot delete the memory after the return and, obviously, if I delete it before, I won't have a returned value. What I was thinking as a viable solution was something like this void func(char*& in) { // blah blah switch make it do something } int main() { char* val = new char; func(val); // Do whatever with func (normally func within a data structure with specific enum set so could run multiple times to change output) val = NULL; delete val; val = NULL; return 0; } Would anyone have anymore insight on this and/or explanation on which to use? Regards, Dennis M.

    Read the article

  • Integer output in Java method not same as pre-converted char value.

    - by David
    I'm trying to parse a simple text file in an integer method and then output an integer from such file so that other parts of the program can use it. For testing purposes it also displays the character value (9 in this case). The integer value for some reason is 57. I've also tried it with another part of the text file (which in that case should be 5, but is instead 53). After looking at an ASCII chart, I see that 57 is the ASCII version of the "symbol" 9 and that 53 is the ASCII version of the "symbol" 5. Is there any simple way I can fix this? I'm getting kind of frustrated as I'm a Java newbie (I've mostly only used FreePascal before this).

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >