When programming C for the command console, what happens when you have a function that tries to use SCANF to ask user input for a CHAR variable, and the user types CTRL+Z (EOF) and hits enter?
For example:
char promptChar()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);
return c;
}
If the user types CTRL+Z ...
The first example does not work when you go to delete the pointer. The program either hangs when I add the null terminator or without it I get:
Debug Assertion Failed Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) from Visual Studio 2008
//Won't work when deleting pointer:
char *at = new char [3];
at = "tw"; // <-- not sure what'...
How do I put strings into an 2D char array from (for example) a file?
char buffert[10][30];
int i = 0;
while(!feof(somefile)) {
fscanf(somefile, "%s", temp);
buffert[i][] = temp;
i++;
}
This will not do it.
...
//In header file: class definition:
class myString
{
public:
myString(void);
myString(const char *str);
myString(const myString &); //copy constructor
~myString(void); //destructor
void swap(myString &from);
private:
char *stringPtr;
int stringLen;
};
//in cpp file, defining them member fun...
We need to pass a format _TCHAR * string, and a number of char * strings into a function with variable-length args:
inline void FooBar(const _TCHAR *szFmt, const char *cArgs, ...) {
//...
}
So it can be called like so:
char *foo = "foo";
char *bar = "bar";
LogToFileA(_T("Test %s %s"), foo, bar);
Obviously a simple fix would be t...
Please could someone explain why this does not work?
char *test = "test";
_TCHAR *szTest = CA2W(test);
And please tell me what I should be doing instead.
Instead of giving me equal text, it's giving me:
...
Is there a quick way to retrieve given character's position in the english alphabet in C?
Something like:
int position = get_position('g');
...
Hello, I am not a very experienced C++ programmer, i get a warning when i do the following:
if (myString[i] != 'x')
{
}
what is the appropriate way to compare these?
thanks for your help!
...
In the following lines of code, I need to adjust the pointer pm by an offset in bytes in one of its fields. Is there an better/easier way to do this, than incessantly casting back and forth from char * and PartitionMap * such that the pointer arithmetic still works out?
PartitionMap *pm(reinterpret_cast<PartitionMap *>(partitionMaps));
...
I found some confusing code during code review and am a bit puzzled. Doing some research I found this situation. I wrote this sample of code to highlight the problem
char d = '©';// this is -87,the copyright symbol , (actually its 169 unsigned)
if(ispunct(d)) // will assert.
{
}
so, the programmer who was bug fixing, did the ...
Hi,
I need to store a char array inside a class and then return it. I have to admit that I'm a bit confused about pointers and have tried everything I can think of but can't get it to work. Here's what I have:
#include <iostream>
using namespace std;
class Test {
public:
void setName(char *name);
char getName();
private:
c...
Hello,
Is there a elegant way to convert 'const wchar *' to 'const char *' on Mac OS X?
Kat
...
I have two strings in a java program, which I want to mix in a certain way to form two new strings. To do this I have to pick up some constituent chars from each string and add them to form the new strings. I have a code like this(this.eka and this.toka are the original strings):
String muutettu1 = new String();
String muutettu2 = new S...
Is it possible to get a char* for a string variable in C#?
I need to convert a path string to a char* for using some native win32 function ...
...
I have a piece of C code that looks like this:
const char (*foo)[2] = bar();
Now bar() is a function that returns a (const void *). How do I properly cast this const pointer? The code produces this warning from GCC : "initialization discards qualifiers from pointer target type". Here are some of my unsuccessful attempts:
const char (...
I keep getting this error: initializer-string for array of chars is too long
Even if I change num and length to 1, it still gets the error:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
const int num = 11;
const int length = 25;
char array[num][length] = { "Becky Warre, 555-1223"
...
Is there a C strings library for C (not C++) that implements an abstraction over char * and wchar_t * strings?
The requirements are:
to be BSD/MIT/CDDL licenced
implements some kind of reference count mechanism
has support for regular expressions
has Unicode support
Thanks,
...
In C, I can do like this:
char s[]="hello"; or char *s ="hello";
so i wonder what is the difference? I want to know what actually happen in memory allocation during compile time and run time.
...
I am using NHibernate against a legacy database which uses Char column types (fixed Strings). I am mapping the char columns to strings in properties. Currently my criteria queries are failing if the value against which i am querying is not padded with spaces such that the length of the string is equal to the char column length. I dont wa...
Hi,
I have a program that is manually generating a pdf using PDFSharp in C#. Although it is rather tedious I have to use it and am nearing completion of the task. Only one issue remains
Problem: I am wondering how I can find out what the width of a given char is for a given font size in Arial
I am having trouble coming up with a more ...