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


ADVERTISEMENT

C++ :: Assigning Value To Struct Variables?

Jul 29, 2013

I'm trying to assign a value to the variables in my struct using the statement:

fscanf(fp, "%s%10s%9s%s", acct.name, acct.num, acct.pin, strbal)

but when I try to access them, it looks like the variables (acct.name, acct.num, acct.pin) are all empty.

Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXAMT 999999.99

[Code].....

View 14 Replies View Related

C/C++ :: Assigning Value From Struct Member To Outside Structure

Jun 20, 2013

I have the code bellow, and i print the data but cannot assign it to global variable.

struct frequency_data {
 char frequency[10];
 int32 frequenca_mesatare;
 int16 PWM_F;
 int32 PR2;

[Code] ....

View 5 Replies View Related

C++ ::  assigning To A Member From Struct Obtained By Overloaded Operator

Jan 27, 2014

I'm trying to assign a value to a member of a struct that I called via an overloaded [] operator. I have the following code for the struct:

typedef struct {
float r, g, b, a;
float operator [](int pos) {
switch (pos) {

[Code] ....

And what I wish to do is

MyStruct a;
a[0] = 0.5;

Is it possible with a struct? How to express this to search engines so I haven't been able to find anything about it. If this is not possible with a struct, is there a way to define something that can do all the following things:

SomeStruct test = {0.5, 0.5, 0.5, 1};
test.g = 1.0;
test[0] = 0.0; // test[0] would be equivalent to calling test.r
float somevalue = test[3]; // test[3] would be equivalent to calling test.a

I hope I've been sufficiently clear.

View 2 Replies View Related

C :: Assigning Value To Char Pointer

Feb 3, 2013

I thought we needed to allocate memory before assigning a value to a char* and also that we needed to use functions like strcpy() to copy something into it. Then how come this works and does not crash?

Code:
#include <iostream>
using namespace std;
int main()
{
char * buf;
buf = "Hello";
cout << buf << endl;
buf = "World!!!!!!!!";
cout << buf << endl;
return 0;
}

View 3 Replies View Related

C++ :: Assigning Char To Array?

Aug 7, 2014

I want to assign a char to an array inside an if statement after the user has input the grade as an integer, but it has to fill an array with characters, such as:

char grades[5];
int grade;
char A, B, C, D, F;
cout << "Enter da grade" << endl;
cin >> grade;
if (grade < 59) {
grade[0] = F;

[code]....

A, B, C, D, and F won't transfer to the array, thus giving me the uninitialized variable error in microsoft visual studio 2010.

View 4 Replies View Related

C++ :: Unsigned Char Array - Assigning Values Converted From Double

Aug 3, 2014

I'm having a pretty weird problem. I've created an unsigned char array for an image buffer:

buffer_rgb = new unsigned char[_w * _h * 3];
memset(buffer_rgb, 0x0, sizeof(unsigned char)* _w * _h * 3);

And I add pixel color values to it like so:

buffer_rgb[i] = ((unsigned char)(col[0] * 255));
buffer_rgb[i + 1] = ((unsigned char)(col[1] * 255));
buffer_rgb[i + 2] = ((unsigned char)(col[2] * 255));

Where col is a 'vec4' struct with a double[4] with values between 0 and 1 (this is checked and clamped elsewhere, and the output is safely within bounds). This is basically used to store rgb and intensity values.

Now, when I add a constant integer as a pixel value, i.e.:

buffer_rgb[i] = ((unsigned char)255;

Everything works as it should. However, when I use the above code, where col is different for every sample sent to the buffer, the resulting image becomes skewed in a weird way, as if the buffer writing is becoming offset as it goes.

These two images illustrate the problem:

tomsvilans.com/temp/140803_render_skew.png
tomsvilans.com/temp/140803_render_noskew.png

You can see in the 'noskew' image all pixels are the same value, from just using an unchanging int to set them. It seems to work with any value between 0-255 but fails only when this value is pulled from my changing col array.

Whole function is here:

// adds sample to pixel. coordinates must be between (-1,1)
void Frame::addSample(vec4 col, double contrib, double x, double y) {
if (x < -1 || x >= 1 || y < -_aaspect || y >= _aaspect) {

[Code] .....

View 1 Replies View Related

Visual C++ :: Error Assigning Pointer To Iterator

Nov 27, 2014

im trying to port a code from vc6 to vs2013 and im having this error

Code:

Error11error C2440: 'initializing' : cannot convert from 'char *' to 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<char>>>' on this line

Code:
vector<char>::iterator BufIt = (char*)lpBuffer;

what i do with this is to stack fragments of data of type char* coming from a socket in buffer to a vector that acts as buffer, I do this since I transfer big chunks of data and the data gets fragmented by the nature of the sockets, I stack the data once its complete I retrieve the final result from the vector.

this code worked flawlessly for long time but now Im trying to port and compiler throws this error, whats the new way to assign a char array pointer to a iterator so i can stack it in the vector.

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++ :: 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/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++ :: 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 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 :: 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++ :: Using Library - Error With Struct Declaration

Jul 30, 2012

Okay so I'm writing a simple program - so far with just 1 header and 1 .cpp file to go with it. I'm getting strange errors saying that my struct hasn't been recognised even though I declare it in the header. The code involved is --

Code:
#include<stdio.h>
#include<iostream>
#include<sstream>
#include"bots.h"
//#include"prisonersDilemna.h"
//write program to battle multiple bots with a random choice generator
//and after all iterations post who comes out on top.

[Code] ....

||=== Build finished: 6 errors, 0 warnings ===|

How should the syntax be? Why does my program not recognise bot as an object type? Why can I not have a void method?

View 5 Replies View Related

C :: Error While Using Struct In Code To Read From File

Jan 31, 2014

I am trying to use struct to store variables from a text file and use them in the main program. I have first tried running the program without using struct and declaring the variables within the main program and it runs fine. But after using struct, it gives no compilation error and a segmentation fault as output. Also, if the size of file/variable size is unknown can I declare variables as char string[]??

The code is as below:

Code:

#include<stdio.h>
struct test {
char string1[10000];

[Code].....

View 4 Replies View Related

C++ :: Error In Reading Struct From Binary File

May 20, 2013

Below is the code for reading a struct that was stored in a binary file. Problem is while reading from file I get the name without first character and age is always equal to zero which it should not be.

#include <iostream>
#include <conio.h>
#include <fstream>
struct abc {
char name[100];
int age;

[Code] .....

View 3 Replies View Related

C++ :: Defining Struct In Separated Class File ERROR

Oct 20, 2013

i've defined an strcuct in .h file and i read its variable in a method in .cpp file ,but i'v got error.

.H file:
class myclass{
public:
struct opt_struct

[Code]....

when i declare the struct without static , it doesn't recognize my struct and with static i face linker error:

Error33error LNK1120: 1 unresolved externals

View 3 Replies View Related

C++ :: Input To Fields In A Struct And Pass Function To Display - Error C2365

Oct 21, 2014

Goal: Use a struct that has 4 fields, input to those fields, and pass to function to display.

Problem: (38) : error C2365: 'displaySData' : redefinition; previous definition was 'data variable'

Code:
#include <iostream>
#include <string>
using namespace std;
//prototypes
void displaySData(MovieData, MovieData);

[Code] .....

View 3 Replies View Related

Visual C++ :: Operator Overload Not Defined Error When Type Accessed Through Const Struct

Oct 17, 2012

I have a basic vector/point class where I've overloaded a bunch of arithmetical operators:

Code:
#pragma once
class point {
public:
point() {
}
point(float p_x, float p_y, float p_z) : x(p_x), y(p_y), z(p_z)

[Code] ...

I can use it fine like

Code:
point p(50,50,50);
point q(50,50,50);
point t = p * q + q;

However when I put this point type into a struct and try to access the members after passing it through by const reference:

Code:
struct sextic {
point a,b,c,d,e,f,g;
};
inline static sextic sexticDifference(const sextic &p_sextic1, c

[Code] ....

This gives me an "operator not defined" error for compilation.

View 2 Replies View Related

C++ :: Converting Int To Char - Getting Error

May 31, 2013

I am tying to convert an int to a char. Below is an example of the code that I have but I am getting an error('=':left operand must be l-value). I am not seeing a problem with the code.

int num = 5;
char temp[2];
char final[2];
itoa(num, temp, 10);
m_pRes->final = temp;

View 4 Replies View Related

C/C++ :: Casting Error Char To Int

Apr 30, 2014

I'm writing a small piece of code that increments through a string of numbers. For every 5 numbers a product is produced. However i'm having an issue understanding an error that keeps occurring.

#include <iostream>
#include <string>
#include <cstdlib>

[Code].....

if you look at the code i've got a string with 5 numbers 1-5 for testing. As the loop increments through the string it takes the first 5 characters and converts them to integers and then a product is returned. The issue is that instead of storing the single letter at position J its storing some combination from the string and as a result gives me a huge product. I tried debugging. I checked what the string[j] value was with a simple cout << and it returned the right number. I even returned the char value before it was converted into an integer and it was the right number.

View 3 Replies View Related

C :: Save Values From A Char Buffer Into Integer Values Of A Struct?

Jul 3, 2013

I'm attempting to save values from a char buffer into integer values of a struct.

This is what resides in the buffer "STD 2 2 2 2 2 2 2 " and this is my sscanf call

Code:
sscanf(buffer, "STD %d %d %d %d %d %d %d
", &dt_struct.date,
&dt_struct.mth,
&dt_struct.year,
&dt_struct.dow,
&dt_struct.hr,
&dt_struct.min,
&dt_struct.sec);

I then print the values back out in a string using sprintf.

Code:
sprintf(t_string, "STD %d %d %d %d %d %d %d
", dt_struct.date,
dt_struct.mth,
dt_struct.year,
dt_struct.dow,
dt_struct.hr,
dt_struct.min,
dt_struct.sec);

But this is what I get:
STD 0 0 2 0 0 0 2

Instead of what I want:
STD 2 2 2 2 2 2 2

View 7 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++ :: String To Const Char Error

Jan 15, 2013

I'm currently finishing up an assignment that was half written by my professor. Below in the testGrades section of code there are two errors both are the same message.

Error: no matching function for call to Grades:: Grades(const char [15])

Test Grades

//Purpose: Test program for the class Grades
// Create stu1 Grades object
// Add 5 grades to stu1 - only 3 can be stored in stu1 - other 2 discarded
// Create stu2 Grades object
// Add only 2 grades

#include <iostream>
#include <string>
#include <iomanip>
#include "Grades.h"

using namespace std;

[Code] .....

View 5 Replies View Related

C/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related







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