cstring

char* as an argument to a function in C

When passing a char* as an argument to a function, should the called function do a free on that string? Otherwise the data would be "lost" right and the program would leak data. Or are char* handled in a special way by the compiler to avoid everyone from having to do free all the time and automatically deletes it one it goes out of scope...

iPhone stringWithCString is deprecated

hi all, I use this code to read data from sqlite database: keyFromSql = [NSString stringWithCString:(char *)sqlite3_column_text(preparedStatement, 1)]; but the compiler give me the warning wrote in the title... so, what is the right and not deprecated method to retrieve a value from sqlite? thanks! ...

What techniques are available to test if a character string is all spaces?

char *p = " woohoo"; int condition = /* some calculation applied to p */ /* to look for all 0x20/blanks/spaces only */ if (condition) { } else { printf("not "); } printf("all spaces\n"); ...

Is it safe to return local CStringW to the caller?

I have a function defined a local variable typed in CStringW, is it safe to return this object to the caller by value, not by reference? ...

How to convert from BYTE array to CString in MFc?

How can I convert a BYTE array in a CString in MFC> ...

Arrays of strings in C

I need to hold an array of C strings. Now I know C strings are just an array of chars so essentially what I want is a 2d array of chars. The strings I'm trying to store will also never exceed 6 characters. My plan is to initialize a char array with 50 "string slots" and then if I hit 50 strings reallocate the array's memory to double it'...

using boost string algorithm with MFC CString to check for the end of a string

I need to check whether my CString object in MFC ends with a specific string. I know that boost::algorithm has many functions meant for string manipulation and that in the header boost/algorithm/string/predicate.hpp could it be used for that purpose. I usually use this library with std::string. Do you know a convenient way to use this ...

cstring trouble for a beginner

Hi I'm trying to make a program that read a file line by line and then put the readed line into a a linked list, my problem is to add the string to list. Look at the code, in the else test you can see my problem. #include<stdlib.h> #include<stdio.h> struct list_el { char *ord; struct list_el * next; }; typedef struct list_...

boost regex search fails with MFC CString

Hi All I having an issue in using Boost regex with a MFC CString. The regex is very simple: it must check if the string ends with the name of a dll I am looking for. In the code below the CString Path DOES contain the dll I am looking for, but I don't know why the regex is failing. Uisng ReleaseBuffer increases the buffer size so the L...

Converter and compresser between ASCII and Binary

Hi I am trying to make a very easy converter/compressor; the program should take a file with 4 different types of ASCII characters and writ it out as binary to a file. The program should also read the binary file and convert it to ASCII and print it out on the screen. Under is my code, I can’t really get the char/cstring. What types of ...

C - Double Pointer getting lost through function call

Hey all, Quick C question here. We've been playing with double, triple, even quadruple pointers recently. We though we had a grasp on things until we ran into this problem... char ***data; data_generator(&data); char **temp = data[0]; printf("printing temp[%d]: %s\n",0, temp[0]); printf("printing temp[%d]: %s\n",1, temp[1]); ...

Proper way to build up a path using cstrings in C++

I need to build up a path to a file. I have the following class method: void Directory::scanDirectory(char *directory) { DIR *dirp; struct dirent *entry; char path[1]; if(dirp = opendir(directory)) { while(entry = readdir(dirp)) { if (entry->d_name[0] != '.') { strcpy(path, directory)...

C++ Storing copy of string in vector of pairs

I have a private attribute in a class that is defined as vector<pair<char *, int> > data;. I add data to this vector with data.push_back(make_pair(p, r));. Later when I go to get the data out of the vector I get bad data for the p value. The data returned is like ��U3. I think this is because a pointer to the char array is being stored. ...

Loop problem. Cin C++ getline clear buffer

I am having a problem, but I cannot figure out what I'm doing wrong. I'm not sure if it's a problem with my loop, or the cin buffer is not being cleaned. I am doing a program that transforms a C-style string to uppercase, however if the user enters more than 11 characters, then the function should only display the first 11, and anything ...

How to Convert CString LPStr

I want to read a value from registry using the following method: char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),m_szDriveName); I tried converting using GetBuffer,m_szDriveName.GetBuffer(0) but this again shows error: error C2664: cannot convert parameter 3 from 'wchar_t *' to 'LPSTR' Edit: Declaration of Met...

char* value gets corrupted during assignment

I have the following code , which gets a return value from a function as char* cDestDrive = ReadFromRegistry(HKEY_CURRENT_USER,NDSPATH,szDestPathRoot); I am able to read the value inside cDestDrive till the time I am assigning it. The moment I am assigning it: CString strServerAddress = cDestDrive; the value of cDestDrive gets ch...