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


ADVERTISEMENT

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C/C++ :: Comparing 2D Char Array?

Jun 22, 2014

I am working on a program to find uppercase, lowercase and digits in a 2D char array. When I try to use an if statement to increase the counter, I get an error "no conversion from 'int' to 'char*'". This is the if statement I am using.

if(myArray[j] <='9' || myArray[j] >='0')

View 7 Replies View Related

C++ :: Char Array Size - Undefined Until User Input

Apr 27, 2014

So I'm trying to make a program, Which has nothing to do with the topic. But I ran into a problem.

I need to get a char array size of 6 doing:

char myChar[6];

but the size (6) is undefined until user input.

So I need to do char myChar[var]; (Var being 6 for now).

When I do:
char myChar[6];
It works!!!

But when I do:
int val = 6;
char myChar[val];
It doesn't work.

View 3 Replies View Related

C++ :: Char Vector - Fixed Size Two Dimension Array

Jun 9, 2013

I want to save the char[8][8] // fixed size 2 dimension array

to a vector

such as

vector<?????> temp;

is there anyway to approach this?

View 4 Replies View Related

C++ :: Output Increases With Dynamic Char Array Size?

Jul 22, 2012

I've been in a strange problem. Im in need to have a dynamic character size, but that increases the outputsize of my program by almost 50kb. (while the program was 11kb previously).

Example:

Char One[7000]; (11kb output)

int Z = 7000;
Char Two[Z];

View 7 Replies View Related

C++ :: Function That Declares Array Of Char Of A Size Of 350000 Elements

Jun 5, 2014

I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).

The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.

What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?

View 2 Replies View Related

C :: Fixing Size Of Array As Opposed To Using A Pointer

Oct 15, 2014

If I have an array and all I have is an upper limit on how big the array can get, and if the number of elements that get added can be considerably smaller than this limit, is it always the right choice to declare a pointer and just reallocate extra memory whenever the array grows? For instance, instead of declaring int a[max] I can declare a pointer int *a and than just realloc when I add elements.

View 1 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 :: 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++ :: 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 View Related

C++ :: Comparing Two Char Arrays Alphabetically

Sep 14, 2013

I want to compare alphabetically two arrays. I try this:

char a[10] = "AABC";
char b[10] = "ZABC";
if(a > b) cout << a;
else cout << b;

But it always outputs a. How can I compare char arrays?

View 3 Replies View Related

C++ :: Comparing Multiple Constant Char At Once?

Jul 4, 2014

I have an array of const char's that are randomly selected in a loop from a list and id like to compare every newly selected choice to be tested against all the others to make sure the same choice isn't given more than once, however the names are lengthy and, for example, using:

for (int x = 0; x<10;x++)//initial loop
while ((choice[x]== choice[x-1] || (choice[x] == choice[x-2]) || etc...)
//^given that I have 10 variables

Would be messy and a painful sight. What would a more convinient way to check each choice?

Edit:It should be said that each choice would then be randomized again and then checked again, and that each newly selected choice is then immediantly used after this. It'll also be assumed that not all the choices have been made when this part runs(ergo choice[3] may not exist yet) as it is in a loop

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 :: Comparing Pointer And Integers?

Mar 25, 2013

I am trying to make a game where you have a secret code that is coded with colors like ROYG (red,orange,yellow,green) and I am having trouble when it tells you when you have a right color in the right spot or a right color in the wrong spot when you guess a color. How can I change my code under the function int comparearray where it will compare pointers to pointers and not integers and give me the correct number of "almost" and "correct".

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 100
#define COLS 4
}

[code]....

View 4 Replies View Related

C/C++ :: Booking System - Comparing 2 Char Variables In Check Function

Aug 31, 2014

I had problem in comparing 2 char vairable in check function

if(room_no==r)

variable r take input from user and compare to room_no read from file.

#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<dos.h>
#include<string>
#include<stdlib.h>

[Code] .....

View 2 Replies View Related

C/C++ :: Comparing Pointer To Variable As While Loop Condition

Aug 11, 2014

I'm writing a delete function for a linked list, and I'm having issues with this bit of code:

void deleteNode(int data){
node* del = NULL;
t = h;
n = h;
while(n != NULL && n->_data != data){
t = n;
n = n->next;
}
}

Or more precisely, this portion:

&& n->_data != data

n is my new node variable, _data is the storage variable in the private section of my class, and data is the information being searched for that needs to be deleted. Everything works without this section of the code. My assumption is that n->_data is somehow wrong, but I don't see how. I've tried everything I can think of- using parenthesis, using the variable rather than the pointer, I've tried expressing the pointer in a different way, I've tried using my t variable rather than n, and I've found examples online that use this exact same expression without any issues.

View 2 Replies View Related

C/C++ :: Size Of Class When Char Member Added

May 25, 2014

Why is the size of an empty class 1? Why is the class still one when I add a char member to the class?//using turbo c++ 3.0, yes I know I'm using a very old c++ compiler and software

View 3 Replies View Related

C++ :: Size Of Structure Pointer

Sep 2, 2014

Is there way to find the size of structure pointer size? When we tried to get the size of structure pointer will get size of address(@ location) which would be 4 bytes long. But I want to get the size of all structure members size using structure pointer.

View 1 Replies View Related

C++ :: Comparing Char And Int - Output Match Or Does Not Match

Feb 21, 2013

My program compiles fine and doesn't have any errors so I am confused as to what the issue might be.

I have a int, which is determined by the user via cin.

I have a char, which is a random word generated from an input file.

1. I want the program to display "The word you entered does match..." if the word entered by the user is the same as the random word.

2. I want the program to display "The word you entered does not match..." if the word entered by the user is not the same as the random word.

The code I'm using for number one is
if (char == "int") cout << "does match..."

The code I'm using for number two is
else if (char != "int") cout << "does not match..."

Basically the programs only outputs "does not match" whether or not it really matches. Even if it matches, it outputs does not match.

Is something wrong with my code?

View 7 Replies View Related

C++ :: Comparing Char Pointers To Integer Pointers

May 21, 2013

I am a little confused while comparing char pointers to integer pointers. Here is the problem:

Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";

When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;

As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};

If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??

View 2 Replies View Related







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