I understand that in order to return a string from a function I have to return a pointer. What I don't understand is why a char array is treated somewhat different from, say, integer, and gets destroyed when you exit the function. That's probably because I come from a high-level languages world, but this seems to be equally valid to me:
...
Hi,
I am trying to understand array declarations, constness, and their resulting variable types.
The following is allowed (by my compiler):
char s01[] = "abc" ; // typeof(s01) = char*
const char s02[] = "abc" ; // typeof(s02) = const char* (== char const*)
char const s03[] = "abc" ; // typeof(s03) = char const* (== const char...
I have just done what appears to be a common newbie mistake:
First we read one of many tutorials that goes like this:
#include <fstream>
int main() {
using namespace std;
ifstream inf("file.txt");
// (...)
}
Secondly, we try to use something similar in our code, which goes something like this:
#include <fstr...
Hi there I'm reading a string and breaking each word and sorting it into name email and phone number. with the string joe bloggs [email protected] 12345. But once i break everything down, the individual separated variables which hold the name,email and phone number have garbage characters at the end of them. I cant figure out why.
test f...
So I want to have a buffer with an array of structs like this:
EventItem
{
tag; // some string or array of characters to describe the value;
value; // some integer or something
}
The value can be anything like int32. What I am concerned about is the tag. If I have an array of these objects, and I make the tag a string, what hap...
Hi all,
i have gone through the numerous questions regarding signed/unsigned char. I understand there are three distinct char types in C++. Currently i have a large code-base which is compiled with Visual Studio - the "default char unsigned" setting is set to "No". Now i'm supposed to add a particular project to our code-base (integrate...
I'm writing a parsec parser which reads in strings and converts escaped characters, as part of exercise 3 here.
For that exercise I am using this function:
escapedCharFromChar :: Char -> Char
escapedCharFromChar c = read $ concat ["'\\",[c],"'"]
I am not to impressed with the use of read to convert the character x into the escape cha...
I have a C array called buf. Here is it's definition:
char buf[1024];
Now, my current code takes from stdin and uses fgets() to set that array, however I wish to use code to set it instead. Right now the line that sets buf looks like this:
fgets(buf, 1024, stdin);
Basically, I want to replace stdin, with say... "My String". What's th...
How do I split a string by char 0 / byte 0 / 0x00 / \u0000 in flash actionscript 3
...
Hello,
I'm trying to define a path at compile time by passing:
-DDCROOTDEF='"/path/to/stuff"'
on the compile line. I then try to get use this in the code like:
char * ptr_path;
strcpy(ptr_path, DCROOTDEF);
strcat(ptr_path,"/MainCommons/CommonLib/fonts/Arial.ttf");
char *pftf=ptr_path;
gdImageStringFT(pimg,brect,iclr,pftf,pts,ang,i...
hello All,
I was able to generate python bindings for a camera library using SWIG and I am able to capture and save image using the library's inbuilt functions.
I am trying to obtain data from the camera into Python Image Library format, the library provides functions to return camera data as unsigned char* .
Does anyone know how to c...
I am reading chapter 2 of Advanced Linux Programming:
http://www.advancedlinuxprogramming.com/alp-folder/alp-ch02-writing-good-gnu-linux-software.pdf
In the section 2.1.3 Using getopt_long, there is an example program that goes a bit like this:
int main (int argc, char* argv[]) {
int next_option;
// ...
do {
next_option = g...
I have a String^1 and I need to convert it to const char* and c_str() does not work as it is not a member of System::String. Is there a simpler way to do this other than this method? I am only doing this once and it is from an openFileDialog->Filename, so the input will not be anything complex. I am using Visual Studio 2008.
Thanks
...
I would like to compare a character literal with the first element of string, to check for comments in a file. Why use a char? I want to make this into a function, which accepts a character var for the comment. I don't want to allow a string because I want to limit it to a single character in length.
With that in mind I assumed the e...
char * function decode time()
{
tm *ptm; //time structure
static char timeString[STRLEN]; //hold string from asctime()
ptm = gmtime( (const time_t *)<ime ); //fill in time structure with ltime
if(ptm)
{
strncpy(timeString, asctime( ptm ), sizeof(timeString) );
//EDIT
sprintf(test, "Sting is: %s", tim...
char out_file_name[30];
ogSize = strlen(FileName); //i.e. - FileName_anylength.log (always.log)
ogSize -= strlen(IN_FILE_SUFFIX); //amount of chars before .log
strncpy( out_file_name, FileName, ogSize ); //out_file_name now is FileName_anylength (without the .log)
Is this the best way to do this?
Also, how do I guard that ogS...
I have const char* FilePathName which looks like this: C:\ImportantFile.hex
And an int id = 12345;
I need to define a new const char* FilePathName_ID that would append the id with an underscore to the original FilePathName to look like this: C:\ImportantFile_12345.hex
I have looked at this but its different as I am using const char* wh...
The code that is confusing me:
set CLEAN=\Users\%USERNAME%\Documents\Directory One\Sub Directory\30% Dalton.txt
IF EXIST %CLEAN% echo "It Works"
This code will never work because the file name has a " % " char
Is there a way to get around this and produce the Echo "It Works"
...
I am trying to find out filetypes using c code, here is the code
char *get_file_type(char *path, char *filename)
{
FILE *fp;
char command[100];
char file_details[100];
char *filetype;
sprintf(command, "file -i %s%s", path, filename);
fp = popen(command, "r");
if (fp == NULL) {
printf("Failed to run c...
Is there a reason for this? I am asking this because if you needed to use lots of empty char, then you get into the same situation as you would when you use lots of empty strings.
EDIT: Reason for this usage was this:
myString.Replace ('c', '')
So remove all instances of 'c's from myString.
...