C :: Assign Numbers In A Buffer To 2D Array

Jul 11, 2014

How to assign numbers stored in a buffer memory to a 2D array.

The data type is unsigned 16bit (unsigned short) integers and they are stored in a 16bit/2bytes*1280*1024=2621440 bytes memory. The pointer pBuffer is the starting address of the buffer. Now I initiated an array and then assign the numbers to the array.

Code:
unsigned frame[1280][1024];
for (int i=0;i<1024;i++){
for(int j=0;j<1280;j++){
frame[i][j]=(*(unsigned short*)pBuffer+1024*i+j);
printf("%u ", frame[i][j]);
}
printf("
");
}

Because I know the number in the memory, I know after running the code that the result gives me nonsense.

I tried frame[i][j]=(*(unsigned short*)pBuffer+1024*2*i+2*j);

Since I think the pointer needs to move 2 bytes at a time, but it still gives me nonsensical array back.

Am I using the wrong expression to assign the values?

View 3 Replies


ADVERTISEMENT

C :: Assign Bit Widths Manually To Numbers?

May 13, 2013

I'm trying to learn how to assign bit widths manually to numbers. Here's my code below:

Code:
#include <stdio.h>
struct node {
unsigned long x : 53;

[Code].....

And I get the following complaint from the -Wall compilation flag, " warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'long unsigned int:53' " which is talking about anna.z, to be specific.

How do I add field width to printf?

View 3 Replies View Related

C++ :: Create Array Of Playing Cards / Assign Values And Suits Then Shuffle The Array

Nov 24, 2014

I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.

void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }

View 1 Replies View Related

C++ :: Accept Integer Array And Its Size As Arguments And Assign Elements Into 2 Dimensional Array

Jan 10, 2015

Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

View 1 Replies View Related

C++ :: Why Assign A Pointer To Array

Jan 15, 2015

Why would you ever assign a pointer to an existing array?Take this link for example. URL....I understand that pointers use dynamic memory allocation so they are much more flexible then a built in array, but if you already have an existing array, don't you already have static memory allocation for that array? Why bother assigning a pointer? Regardless of the pointer, doesn't the program still allocate static memory to the array anyway?

View 3 Replies View Related

C++ :: Assign Value Of Pow (2,800) To Char Array Or String

Jan 31, 2015

Assign value of pow(2,800) to char array or string ....

View 1 Replies View Related

C++ :: Assign Object Into Unordered Map Array?

Jun 17, 2013

typedef tr1::unordered_map <string, pin *> pin_cmp;
pin_cmp _pin_cmp;
_Pins[_num_pins] = new pin (pin_id, _num_pins, s, n, d);
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling

What actually the code doing?

_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling

I am not familiar with unordered_map which still can use with array[].I am confuse unordered_map just need key and value why will have array[]?

View 1 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++ :: 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 :: Get First Integer From A File And Assign It To A Variable And Others Integers To Array

Jun 2, 2013

what I need is to get the first integer from a file and assign it to a variable and the others integers to an array. Example: Thats my file content 5 4 6 7 8 0 and that would be the code:

Code:

struct Array{
int n;
int *v;
}

[code]....

View 8 Replies View Related

C++ :: Loop Through Indexes In Guess Array And Assign M Randomly

Jan 19, 2013

Just run a loop through each of the indexes in the guessarray and assign 'M' to them randomly.

View 2 Replies View Related

C++ :: How To Assign Array To Every Element Of Another Array

Mar 29, 2014

I have been given an assignment which I understand pretty well, but I have a problem, and haven't been able to find a clear solution anywhere. I'm sort of a beginner in all this, so it's hard to understand what some people say.

So basically what I wanna do is assign a set of grades to every element in an array of a set number of students. I already have the part where you ask for the number of students you want to enter and then ask for their names and grades, but it can only enter one grade, and I can't figure out how to assign several grades and then get the average.

Here's my code, the assignment said to do it like this.

#define MAX 100
#include<iostream>
#include<stdlib.h>
#include<string.h>

[Code]....

View 1 Replies View Related

C++ :: How To Assign Char Array As User Defined String Object

Apr 17, 2014

STRING s1 = “FOOBAR”

Here STRING is a user defined class. how to assign a constant char array "FOOBAR" to string object? Copy constructor need to be same class type as parameter. and overloading assignment operator also need to be same class type. I think 'friend' can let pass another type of object rather than STRING to do operation on overloaded '=' operator. How could it be done if it is possible at all?

View 2 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.

I'm stuck on how to put the prime numbers into an array.

The input file has the numbers 1 & 100.

Here's what I have so far.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");

[Code] .....

View 1 Replies View Related

C :: Find Duplicate Numbers And Numbers Found Once In Array

Dec 7, 2013

Question: How to find a duplicate numbers and numbers found once in array.

View 7 Replies View Related

C/C++ :: Generate Combinations Of Numbers From 1 To 25 In 15 Numbers Array?

Sep 21, 2014

The code below will generate combinations of numbers from 1 to 25 in an 15 numbers array. The only filter I've applied is that the sum of all the numbers in the vectors divided by 15 needs to be between 13 and 14.
I would like to count how many consecutive numbers there are in one combination, so that later i can apply another filter.. for example:

1 3 4 5 6 8 10 13 14 16 17 18 19 20 25

3 + 4 = 1
4 + 5 = 1
5 + 6 = 1
13 + 14 = 1
16 + 17 = 1
17 + 18 = 1
18 + 19 = 1
19 + 20 = 1
_____________

Count = 8, in this case..

I think it's not very difficult to do, but i just can't see how to do it.

#include <iostream>
#include <vector>
#include <numeric>

[Code]....

View 3 Replies View Related

C++ :: Starting Vertex Array Object At Index Of Vertex Buffer Object

Sep 22, 2014

I'm trying to figure out how I can create a vertex array object at offset of a vertex buffer object.I've created the buffer object. I'd like the "texs" idnex data to start at the texture coordinate content of the vertex_t structure.

Type definitions:

struct vertex_t {
vector3d_t position;
float s; // Texture coordinate s
float t; // Texture coordinate t
};

Code so far:

// How do I make this start at a certain spot of the VBO?!
glVertexAttribPointer(texs, 2, GL_FLOAT, GL_FALSE, sizeof(vector3d_t), nullptr;
//...

View 1 Replies View Related

C++ :: Storing Numbers Into 2D Array - Invalid Types Int For Array Subscript

May 17, 2014

#include <iostream>
#include<fstream>
int decryption(int);
int multiply(int,int[][2]);
using namespace std;
main(){
int n;
ifstream inFile;
inFile.open ("out.txt");

[Code] .....

I was trying to store numbers read from a text file into 2D array but I am getting the error above.here is where the error occurs:

line 33: cout<<m[i][j]<<" ";

View 4 Replies View Related

C# :: How To Get Rid Of New Line In Buffer

Oct 29, 2014

I have an int array of size 5 and I have my program to accept 5 integers between 10 and 100 inclusively. I should be able to type integers over and over again until I get 5 that are in the range, 10 <= x <= 100. Now when I get 5 that fall in that range the program should continue but instead it wants a 6th number before continuing. I'm suspecting the program is hanging on to a new line character. Anyway to ignore the new lines? Couldn't find anything for C# without clearing the screen.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DupElim {
//dup elimination

[code]....

View 5 Replies View Related

C++ :: Assign Value To Interval

Oct 2, 2014

This is my code , i should Assign value val to interval [keyBegin, keyEnd).

#include <assert.h>
#include <map>
#include <limits>

void assign( K const& keyBegin, K const& keyEnd, const V& val ) {

if(!(keyBegin<keyEnd))

[Code] .....

View 7 Replies View Related

C++ :: Assign Value Dynamically?

Jun 18, 2013

I have array of pointers and when i tried to assign values dynamically all array items have the same value which is last value.

char* list[];
int DynamicDemo(void)
{

[Code].....

View 2 Replies View Related

C :: Passing Snprintf Into A Buffer?

Oct 17, 2014

Im creating a permissions profiler in c by using stat()I ran into a problem of getting a bad address as in my path. Ive tried multiple solutions with no dice, and now I have one more solution I want to try but I dont understand how.how do you use a snprintf and pass that into a buffer, and pass that into a path for stat()?

View 9 Replies View Related

C :: XOR On Char Buffer Fails?

Jan 12, 2015

I`ve wrote a function for my utility to XOR char* buffer by a key, then to reverse it with the same key. Here is the code, it`s simple enough:

Code:

static inline char* XOR_buffer(const char* d, const char* k ) {
char *newstr = (char*) malloc(sizeof(char)* strlen(d));
newstr[0]='';
printf("%d is size of string
", strlen(d));
char *begin = newstr;
char* ret = begin;
int len = strlen(k);
}

[code]....

The lengh of the string is reduced by the second XOR call. You can try it out, just define XORDBG to view the error message in the second pass to the buffer.

View 9 Replies View Related

C++ :: Use Const Char As Buffer?

Feb 5, 2014

I want to use a const char* as a buffer. I am reading values from a file and adding them to a buffer. How to extract the values is simple enough. I am reading through a filestream, reading each character into a char pointer and progressing that char pointer every time. I have another char pointer marking the start positon

eg.

char *mychar = new char;
char *char1 = new char;
char *char2 = new char;
const char *constchar ;
char2 = char1;
while(filestream.read(mychar,1) {
*char1 = *mychar;
++char1;
}

Then I get this problem: constchar = mychar; // const char* = char*.

Constchar does not catch all the data in other words. At some stage some data is lost due to zeros in the data.. How can I put values into a const char and get around this problem? The const char* will //only record everything up until the first zero.

View 6 Replies View Related

C++ :: Buffer Not Writing To File?

Aug 22, 2014

suddenly nothing is written to my file

void taglessLine(char line[],ofstream& buffer){
buffer.open("buffer.txt", ios::out);
int len=strlen(line);

[Code].....

View 2 Replies View Related







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