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


ADVERTISEMENT

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

Jun 5, 2012

"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);

[Code] ....

These codes give these errors:

error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'

These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"

I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.

View 3 Replies View Related

C :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

#include <stdio.h>
#include <stdlib.h>

[Code] ....

View 4 Replies View Related

C++ :: Using Struct / Char Array For Tic Tac Toe Game

Feb 11, 2014

I basically just want a function that tells me if 'X' or 'O' won in a tic-tac-toe game. I don't care about the visuals, I just want a function that tells me if 'X' or 'O' won. If X wins, return 0. If Y wins, return 1.

How to do the diagonals, but as far as the across and down wins, I know I have to use a nested for loop, but am a little stuck, as to exactly how to set it up.

#include <iostream>
using namespace std;
struct TTT{
char array[3][3];
unsigned moves;

[Code] ....

View 1 Replies View Related

C++ :: Assign String To Char Array Of Struct

May 6, 2013

#include <iostream>
using namespace std;
struct box{

[Code].....

C++Dev.cpp:23: error: incompatible types in assignment of ‘const char [15]’ to ‘char [40]’

View 2 Replies View Related

C :: Initialize Data Member In Struct

Mar 28, 2013

I was looking at some linked list material and was wondering something. Can you initialize a data member inside a struct like in C++? i.e.

Code:
typedef struct node
{
int data;
struct node * next = NULL; // this is the line in question
} LLnode;

View 3 Replies View Related

Visual C++ :: Can't Initialize Struct With CString

Apr 7, 2013

I'm trying to compile the following and it doesn't work? How can I get the CString to initialize.

Code:

struct print {
int x; //row
int y; //col
int fid;
CString *data;
char *format;

[Code] .....

the char *format is not a problem, but compiler doesn't like CString *data;

tried CSting data and that also doesn't work, typecasting didn't work either?

View 14 Replies View Related

C/C++ :: Possible To Initialize Char Value Into Int Value?

Oct 13, 2012

#include<stdio.h>
int main() {
    int j=printf("Hello.");
    return 0;
    exit(10);
}

In the above program is it possible to initialize int j with char value "Hello."?

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++ :: 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++ :: 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++ :: 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 :: Initialize A Pointer Variable With A Knowing Address?

Dec 28, 2013

I need to initialize a pointer variable with a knowing address. See code below, ptr is the final destination and value of ptr_address contains the address value, so I need to do something like ptr = *ptr_address.

Code:

int *ptr;
int *ptr_address;
int address;
address = 0x10000005;
ptr_address = &(address);
ptr = *ptr_address;

The problem is that compiler gives the following warning message:

warning: assignment makes pointer from integer without a cast [enabled by default]

Is my code wrong or there is any other way to do it without receiving this compiler warning?

View 3 Replies View Related

C/C++ :: Declare And Initialize A Pointer To Variable Int Cost

Mar 2, 2014

this question would their be a different process if they asked "declare and initialize a pointer to the variable int cost[N][N]" Here's what I have so far

[#include<stdio.h>
int main() {
int a; // Step 1
int *ptr; // Step 2
a = cost; // Step 3
ptr = &a; // Step 4
return(0);

[Code] .....

View 5 Replies View Related

C :: Printing A Char String From A Struct

Jan 3, 2015

I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.

the function looks like this:

Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;

[Code]...

the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):

View 7 Replies View Related

C++ :: Error On Assigning New Char Value From Struct

Feb 17, 2015

Well I tried to assign a new char value from a struct to another char variable but I got the "Cannot convert 'int' to 'char'" error when compiling. I've tried several alternations but I still can't get away with this error.

Here's a section of the code:

javascript:tx('code')
for(int i = 0 ; i < 10 ; i++){
pts[i].dist = sqrt((pts[i].x*pts[i].x)+(pts[i].y*pts[i].y));
}

[Code].....

View 1 Replies View Related

C/C++ :: Ordering Element (char) In A Struct

Dec 9, 2014

what is the function of ordering element(char)in a struct

View 1 Replies View Related

C :: How To Use Pointer To Struct

Mar 6, 2015

how can I call and print the Pointer:

ptr->address
Code: #include<stdio.h>
struct account {
int address;
int value;

[code]....

View 5 Replies View Related

C :: Appcrash Segmentation Fault Char Inside Struct

Apr 24, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct info info;

[Code] ....

View 2 Replies View Related

C/C++ :: Source Code Containing Struct Pointer

Mar 9, 2015

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
struct stock{
char symbol[5];
int quantity;
float price;

[Code] ....

- In the final output
Value
%.2f

- How is the final pointer reference at line33 leading to the output %.2f ? (i do understand that the %% is used to display a %] ....

View 1 Replies View Related

C/C++ :: Printf Several Values Of Struct Pointer?

Jan 14, 2015

I am currently trying to printf several values of a struct pointer but with little success.

#include"Header.h"
/*
In header:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct FileStruct {
char FileQuestion[64];
[Code] ....

As you can see I am trying to re-crate the output from the first loop in my second loop, however it is with little success. The second loop's first run re-crates the last output of the first loop and if I use FileStructPointer++ or -- the output goes broke.

See attached for how it looks in the console window.

Attached image(s)

View 3 Replies View Related







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