C++ :: Why Cannot Copy String Pointed By Pointer To Array Of Char

Feb 22, 2013

I have this function in a class: and a private declaration: how can I copy the parameter "ProductName" to allowedProductName. I tried all combination and I can't get it to compile.

private:
StatusPanel &statusPanel;
char allowedProductName[MAX_NAME_LENGTH];

[Code].....

View 9 Replies


ADVERTISEMENT

C++ :: Enforcing That A Function Does Not Modify Dynamic Array Pointed To By Pointer

Aug 21, 2014

In case the question was not very clear. Say I have the following code:

int sum(int * x, size_t N){
int sx;
/* returns sum of elements in x */
return sx;

[Code] ....

I'm curious to know whether there is a way that ensures a function does not modify the memory pointed to by a pointer.

View 9 Replies View Related

C++ :: Delete Member Of Vector That Is Pointed By Pointer?

Apr 17, 2013

I have following:

struct Point {int* a; int b;};
vector<vector<Point> > numbers;
vector<int> example;

The numbers vector has a matrix of a sort and each of the members are pointing to one member in the example vector. A member numbers.at(2).at(3).a is pointing at example.at(3). Now, can I remotely delete a member in the example vector using the pointers? Like so:

delete (*(numbers.at(2).at(3).a));

I know there is a more convenient way to delete members, but this is a very specific case I'm working on.

View 3 Replies View Related

C++ :: Copy Unsigned Char Array Into Another

May 7, 2013

I am having some trouble performing this. I am not sure, if my unsigned char arrays are null terminated, but I don't think so. Here is my code: They are supposed to be byte arrays of size 16.

int setkey(unsigned char* ky) {
printf("INSIDE POLY-DEL ... key byte array passed in HEX:
");
int i;
for (i = 0; i < (int)16; i++)

[Code] .....

View 12 Replies View Related

C++ :: Copy Array Into Pointer

Jun 20, 2013

I have written this code, and at first glance it does what I want, however I am worried that

a) I am overwriting the array that is apssed from chord.getPattern()
b) Im getting a memory leak that I want to get rid of, and
c) is there generally a /what is the neater way to do it:

Code:
uint8_t* ChordBuilder::invert(uint8_t count, Chord chord) {
temp = chord.getPattern();
chord.invert(true);
//TODO count is how many times to invert. Moves root aswell however

for (uint8_t i = 0; i < count; i++){

[Code] ....

temp is a member variable of ChordBuilder - and is expressed as: Code: uint8_t* temp; I dont want the pattern that chord stores, and passes with getPattern() to change - I fear it is at the moment?

I would rather not use the "new" but I cant think how to get rid of it, however Im not sure where I would need to put the "delete"?

View 7 Replies View Related

C++ :: Binary Char Pointer Into String

Jun 12, 2013

Is there a more simple method to copy Buf into str? Buf is a binary string.

Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}

View 5 Replies View Related

C++ :: Converting Char Pointer To String

Mar 5, 2013

Here's the code I'm working on:

string* arrayPush(string *array, char **toks){

if(array[sizeofHistory -1].empty()){
//find the next available element
for(int i=0; i < sizeofHistory; i++ ){

[Code] ....

toks is an array of pointers to strings. I need to assign a toks to array[i].

View 10 Replies View Related

C/C++ :: Pointer-to-char To String Literal?

Oct 6, 2014

how string literal that works with the cin object?

char * str = "This is a string constant";

Is the str stored the address of the first character of the string literal?

But some books just state that the pointer-to-char (char pointer) stores the address of the string literal". So just wonder how it is.

When it is used with cout, cout just treats it like a string and instead of printing the address, it just prints out all characters one by one until it reaches the terminated null character.

If this is the case, then I am just wondering how cin works with it? with a statement like this cin >> str; ?

Does the computer allocate enough memory for it? and then cin stores the first character into the first address and then advances to the next address and stores the next character?

View 1 Replies View Related

C++ :: Unable To Compare A String With A Char Pointer

Jan 28, 2013

Ok, I'm having a few problems with strings, mostly string functions saying they're not able to compare a string with a char pointer.

int main()
{
int counter = 0;
int x, y, z;

[Code].....

My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).

View 2 Replies View Related

C++ :: How To Copy A String To Array

Sep 14, 2014

#include<iostream>
#include<string>
using namespace std;
int main(){
char char_array[10];
int ascii_array[10];

[Code] ....

I have been trying for a while to copy a string to an array, i know i can copy an char_array element to a string but its with a two dimension. How can i do this? i want it to be user entered.

View 3 Replies View Related

C/C++ :: Copy A String To Array Of String

Mar 27, 2014

I am trying to copy a string to an array of string. I have used these two examples before and they have worked so I don't understand why they won't work this time. I am getting a segmentation fault.

[URL]...
[URL]...

I remembered to initialize everything.

char *strings_mneumonic_table[503] = {0};
char mneumonic[20] = {0};
int start_address = 0;
int hash = 0;
if(line[0] == 32)

[Code]...

Here is my output

hash is 2
little start
BIG START
32 group
mneumonic is START
hash is 2
Segmentation fault (core dumped)

View 6 Replies View Related

C++ :: Using A Pointer To Char Array

Aug 31, 2013

I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.

#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;

[Code] ....

View 3 Replies View Related

C :: Pointer To A Char Inside Array

Jun 7, 2013

Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...

Code:
#include <stdio.h>
int main (void)
{
const char *pointer;
const char alphabet[] = "ABCDEFG";

pointer = &alphabet[5];
printf("pointing to %c of the alphabet
", pointer);
return 0;
}

Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.

View 5 Replies View Related

C :: How To Assign Values To Pointer Char Array

Aug 10, 2013

I can assign values to pointer character array like this...

Code:

char *array[4]={"abc","xyz","dgf","sdt"} ;

but the case is i don't know how to assign strings through key board ???? with using gets ,getchar or other suitable function

View 2 Replies View Related

C :: Array Of Char Pointer Type Mismatch

Apr 20, 2013

I have an array of char pointers:

Code: char *input_args[MAX_ARGS];

And I have this function:

Code: BOOL parseArgs(char **input_args[], input arg_num);

I am trying to pass a pointer to this char pointer array like this:

Code: parseArgs(&input_args, args_num);

But the compiler is complaining:

Code: warning: passing argument 1 of 'parseArgs' from incompatible pointer type ...

note: expected 'char ***' but argument is of type 'char * (*)[20]'

Tried a bunch of stuff but nothing works.

View 4 Replies View Related

C++ :: Char Array Reversing Function Using Pointer?

Feb 4, 2014

Why does this code doesnt work?

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class my_string {
char* ptr;

[code] ....

View 1 Replies View Related

C++ :: Initialize Char Pointer Array In Struct

Nov 28, 2014

I am trying to store data in a struct to be able to read it latter . have problems initializing this.

struct FoodAndDrink {
struct Food {
char* CannedGoods[2] = {
"Canned Spaghetti",
"Canned Tuna",

[code] .....

View 7 Replies View Related

C++ :: Size Of Char Array - Comparing Name To Another One (Pointer)

Jul 13, 2013

I have function that looks like this myfoo(char* Name) Now i want to compare this name to another one . But the another name is a pointer . This my code :

bool Tribe::RemoveSurvavior(char *H_Name) {
const char *p;
p=SurpointArr[i]->GetSurvivor_Name();
}

I need to compare if p is same as H_Name.

Mine is do it with for on each element but when i use sizeof it gives me size of char and not real size of the name.

View 6 Replies View Related

C :: How To Stop Passing Char Array Index As Pointer

Dec 23, 2013

I am trying to write a light weight printf style function.

I have got this far:

Code:

void println(const char *txData){
LOG(__PRETTY_FUNCTION__);
UARTPuts (LPC_UART0, txData);
}
void miniPrint(const char *format, ...)
{
unsigned int index = 0;
va_list argptr;
va_start(argptr, format);

[Code]....

I understand why I think. When I am passing the reference to the array possion it is outputting everything up to the next /0. So my question is how do I stop it?

I dont have much choice as to how the output wants it:

Code: void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)

Thats library code, so I dont want to change it. I.e I have to pass an address into println.

View 1 Replies View Related

C++ :: Wrong Return Type When Returning Char Array As Pointer

Apr 25, 2014

I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.

Here is a snippet:

Code: class Player
{
private:
char state[MAX_STATE_CHAR + ONE_VALUE];
int rating;
char last[MAX_NAME_CHAR + ONE_VALUE];
char first[MAX_NAME_CHAR + ONE_VALUE];
int groupNumber = NEG_ONE;
public:
char * GetFirst() const
{
return first;
}

Visual studio is saying that the return type doesn't match.

View 3 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

Apr 20, 2013

I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.

// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);

[Code] ....

View 3 Replies View Related

C :: Copy Every Single Character From One Char Into Another

Jun 5, 2013

I have some problems with copying a single character from one char into another. How do I do that? Here is the function I am using

Code:

void
text_col (char line[]) {
char line1[1];
int l, ii;
l = strlen(line);

[Code] ....

I am trying to copy in a loop every single character from char line into char line1. That is not working.

View 8 Replies View Related

C++ :: Char Array To String

Oct 19, 2013

I have some code:

char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);

After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".

Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.

Or is there something I'm missing? Maybe the termination character, or something.

View 1 Replies View Related

C++ :: Converting String To Char Array

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.

Code:

//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 1 Replies View Related

C :: Convert Char Array To String

Oct 15, 2013

Currently I have:

Code:
char my_array[4] = { '1', '2', '3', '4' };

how do I convert the above to a string of: "1234"

View 6 Replies View Related

C :: How To Convert A String Into 2D Char Array

Mar 8, 2013

.I have this string that I need to convert into a 2d char array like this:

String str= "A,E,B,I,M,Y#N,R,C,A,T,S";

I know how to use delimiter and split string and I know how to convert but only from string to char[].I need something like this:

Input: String str= "A,E,B,I,M,Y#N,R,C,A,T,S";

Output: [A] [E] [B] [I] [M] [Y][N] [R] [C] [A] [T] [S]

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved