C++ :: Signal Or Array Or Vector Shifting?

Dec 6, 2013

This can be done very easy, but I assume there is a better way to do it.

assume that I have a vector or a signal like

x=[1 1 1 1 1]

want to shift it by one unit to the right I have

x[n+1] gives

xn=[0 1 1 1 1 1]

and x[n-1] vies

xn=[1 1 1 1 0]

as you can see the length of the original vector or array does not change.

How can I solve this problem without specify the length of the output vector. The size of the output array should be the same as the input array, but I couldn't find a way to do it without adjusting the size.

View 2 Replies


ADVERTISEMENT

C/C++ :: Shifting Elements In Array?

Jan 2, 2015

Let's say I have an array of 10 elements. I want user to enter 9 numbers so that they fill arrays 0 to 8 (9 numbers). Now I shift the arrays +1. so array[0] is now array[1] and so on. Now I ask user to enter 10th number (fills array 0).

Here's my code(it doesn't shift arrays and doesn't ask for 10th num)

#include <stdio.h>
int main() {
int a[10];
int i;

[code]....

View 4 Replies View Related

C :: Shifting Elements In 2 Dimensional Array

Feb 28, 2013

I am inserting elements from two files into 2-D arrays.Suppose I have generated this kind of code to create 2-D array:

Code:

main() {
int counter;
int divide=5, m1=0, l1=20, window=20;
for(counter=0;counter<divide;counter++){
for(i=m1,j=0;i<l1;i++,j++){
}

[code]....

Now after generating 2D array, if I want to shift last 2 elements from windata[counter] or winquery[counter] where counter=0 to the beginning of counter 1 and subsequently last two from counter 1 to counter 2 in this fashion, how can I do that.

View 4 Replies View Related

C++ :: Bit Shifting - Cache Simulator

Apr 18, 2013

I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to acquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache.

View 6 Replies View Related

C :: Cache Simulator - Bit Shifting

Apr 21, 2013

I'm attempting to make a cache simulator in C++. But I need to access individual bits in an integer to figure out where in my "cache" the writing actually gets done. I'm pretty new to bit shifting. Say I'm trying to access the the bits of the int 5, which are its "address". I'm simulating a direct mapped cache. I need to find its tag, the set it goes into, and which line. How do I use bit shifting to access the bits to aquire the tag, the index bits, offset bits, block number...all these pieces in order to actually find where I store it in the cache. I need to break the bits up into 3 sections: tag, set index, and block index. I think I can figure out the set and block index sizes based on the values passed in. The tag bits are just the remaining ones. And I'm hard coding values such as cache size (C) - 1024, number of physical address bits (m) - 32, block size (B) - 2, number of lines per set (E) - 1 (again, directly mapped cache). How would this look? I'll be using unsigned longs, so it can handle up to 64 bits.

View 3 Replies View Related

C++ :: Shifting Bits Away And Back

Mar 25, 2014

Value x is a 32-bit unsigned integer 3:

00000000000000000000000000000011

If we use bitwise-shift to shift all bits to the right by 2, x is 0:

00000000000000000000000000000000

If we then do a bitwise leftshift on x by 30, do we end up with:

11000000000000000000000000000000
or
00000000000000000000000000000000

In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?

View 2 Replies View Related

C++ :: Pointers / Binary Data And Shifting

Sep 15, 2014

unsigned short foo = 1337;
//since unsigned short is 2 bytes, a char x[2]should be enough to hold the binary data
char foo2[2];

How do I have foo2, contain the binary equivalent of foo? (how can I point foo2 to = &foo)

View 4 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C :: Signal Function Defined Twice With No Error?

Dec 13, 2013

I'm using a library in my code in a file called "my_signal.c". In this file I've defined this function:

Code:
Sigfunc * signal(int signo, Sigfunc *func){
struct sigaction act, oact;
...
}

Since the signal function is also in file signal.h and I included it in "my_sygnal.h" file, I'm wondering why the compiler did not say anything about this "double declaration" of the function with the same name.

View 9 Replies View Related

C :: How To Signal End Of Standard Input Using Scanf

Oct 30, 2013

so i'm using scanf() this way

Code:

int i;
while (scanf("%i", &i))
printf("%i ", i);
printf("
done
");

i tried several combination of Ctrl+D and "Enter", it's not terminating, Ctrl+C just "cancels" the whole thing without printing "done", i'm running this on linux installed on a PC

View 9 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related

C :: Program Received Signal - Segmentation Fault

Sep 29, 2014

gdb result is

Code:
Program received signal SIGSEGV, Segmentation fault.
isoc99_fscanf (stream=0x0, format=0x4014e0 "%u %u %u %u")
at isoc99_fscanf.c:30
30 isoc99_fscanf.c: No such file or directory. Code:

[Code].....

View 2 Replies View Related

C :: Linux IPC Implement Signal And Slot For New Message

Dec 4, 2014

I'm new in IPC. I would like to implement a signal of a new message, which calls the slot function, eg .:

Code:
msg_on_newMessange(type, &slotFunction);

My code:
Header file: messages.h
Parent file: parent.c
Child file: child.c

How can I do this ?

View 2 Replies View Related

C :: Program To Execute Foreground Process - Signal Handling

Feb 3, 2014

I am trying to create a program that would execute a foreground process. I have this code for the foreground process

Code:
#include <stdio.h>
#include <signal.h>
int main() {
int temp;
printf("We are in the current program

[Code] ....

And this is my main program

Code:
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int main() {
signal(SIGINT, SIG_IGN);

[Code] ....

My main program stops executing after the process "./scanf" executes and there fore does not print the line "How are You"...

I want to main program to continue executing after "./scanf" finishes. How to achieve that?

View 2 Replies View Related

C/C++ :: Setting Signal Handler - How To Access Class Member

Dec 4, 2014

I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem. My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members. I understand that compiler should know that this class instances will exist during all program execution. I have tried to set static member class Foo instance in another class , but this didn't solve the problem. How to correctly implement signal handling in such case.

Here is example of my code

class MyContainer {
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] ....

View 1 Replies View Related

C++ :: How To Access Class Member And Methods From Static Method (signal Handler)

Dec 4, 2014

I am writing my program on C++ language. I have one promblem. I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem.

My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members.

I understand that compiler should know that this class instances will exist during all program execution.

I have tried to set static member class Foo instance in another class , but this didn't solve the problem.

What is correct approach to do this. How to correctly implement signal handling in such case.

Here is example of my code

Code:
class MyContainer{
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] .....

View 4 Replies View Related

C/C++ :: Send Signal SEGV To Crash A Running Process In Windows To Dump Core

Jul 2, 2014

I need to do an equivalent of kill -11 <pid>(which is in unix) in windows.

I need to crash a process with SEGV so that it would dump core in windows. Is there any tool by which we can do this . Also is there any sample code through which we can achieve this .

In windows we have taskill which only terminates a process , but is unable to send a signal like SEGV to the process upon which it would terminate and dump core .

View 9 Replies View Related

C++ :: Errors With Unresolved Token And Unresolved External Signal

Jul 10, 2013

My program will not run because of error LNK2028 "unresolved token" and error LNK2019 "unresolved external signal" and I do not know why. My teacher says that I need to make the constructor and display functions display class variables in different formats, but I do not know what to do with that. Here are my 3 files:

Header take 2.h:

#pragma once
#include <iostream>
#include <string>
using namespace std;
class Heading {
private:
string company, report;

[Code] ....

Here are the errors:
Error1error LNK2028: unresolved token (0A0003C9) "public: __thiscall Heading::Heading(void)" (??0Heading@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)c:UsersOwnerdocumentsvisual studio 2012ProjectsClassLibrary2ClassLibrary2Source1.objClassLibrary2

[Code] ....

View 2 Replies View Related

C++ :: Should Use Vector Or Just Double Array

Dec 15, 2014

I am programming about some numerical problems. I know that vector supplies vector operations. But vector always allocate more memory (used when the size changes). My matrix or array never change size, and the vector operation is just +,-,dot,cross,distance

My question is that should I use vector, or simple double array with new & delete is enough for me?

View 6 Replies View Related

C++ :: Array Or Vector Of Widgets?

Oct 1, 2014

I am trying to create an array of objects. I have to be abstract unfortunately (can't show you all my code), but this is the general gist of what I'm doing. Let's say these objects will be Widgets.

I would assume a vector of widgets would be better than an array due to it's flexibility. So if I use an array, let's say that my widjet is called MY_WIDGET and MY_WIDGET has a constructor of MY_WIDGET(int x, int y);

I have tried using an array to hold several widgets like this.

int i = 10; // obviously this number will be decided dynamically.
int x = 10;
int y = 10;
MY_WIDGET *array[i];
for(int x = 0; x < i; x++)
{
arr[x] = new MY_WIDGET(x,y);
y +=30; // moves the next widget down so they don't cover each other.
}

So now I have an array of objects or Widgets in this case. I'm only using widgets for this example because I want to display the use of a constructor.

So, while my compiler (MinGW) will let me do this, I still get an error at runtime because of the way I have dynamically sized my array 'arr[i]'.

The usual way of doing this, let's say for an int (see below), I can't apply for an object with a constructor requiring multiple parameters to construct it. Maybe I can't, I'm not sure.

int *x = 0;
x = new int[10];

This begs the question, should I be using a vector and if so, how do I dynamically push_back constructed objects into a vector without running into the same problem above. I have tried the below and get problems at compile time telling me that 'the base class is private within this context'. Not sure how to go about this but if I can understand how to dynamically create objects with constructors and add them to a vector or array I should be able to do this.

vector<MY_WIDGET> myvec;
MY_WIDGET the_widget(x,y);
myvec.push_back(the_widget);
y+=30;

View 4 Replies View Related

C++ :: How To Load WAV Files In Vector Or Array

Feb 28, 2013

How to load .wav files. Say there are several .wav files in a folder called "sounds" in "My Documents", what would be the steps on loading them in a vector or array. I'm thinking I should use a vector type of array to not worry for a fixed size.

View 3 Replies View Related

C++ :: Parsing Multidimensional Vector Into Array

Nov 30, 2013

For a rather complex and strange reason that I won't explain right now, I need to have this going on in my program.

class FVF{
private:
vector<vector<float>> data; //Contains fvf data for Direct3D stuff
public:

[Code].....

The FVF allows this Model3D class to also be compatible with file handling methods I've got, but here's the problem. D3D buffers require an array to feed them the information, and I know that for a single dimension of vector I can use vec.data(), how to do this for multiple dimensions.

I think the best Idea I've got so far is to set the vector within the Model3D class as a pointer, then I can union it with a float pointer... Once I can guarantee the information is correct and complete, manually transfer the contents of the vectors into the float pointer.. (The union is to reduce memory needed instead of having the data repeated in vectors and arrays)

how I could just pass these as arrays?

View 4 Replies View Related

C++ :: How To Change 2 Dynamic Array Int Vector Class

Oct 29, 2014

// dynamic memory for 2D char array
char **board = (char**) calloc(column, sizeof(char*));
for(int i=0; i<column; i++)
board[i] = (char*) calloc(row, sizeof(char));
//for char 255 row and colum
char temp[255];
inputFile.getline(temp,255);

[Code]...

so i want to change into vector class like Vector<board>row;

View 8 Replies View Related

C++ ::  passing 2D Array Created Using Vector Container

Feb 10, 2014

I am trying to pass a 2D array called f (coming from a text file with 9 columns of numbers and 297,680 rows) that was created using the vector container in my main() to the function myfunc. I'm just trying to figure out how to pass the address of f in main() to myfunc(), so that myfunc() has arguments consisting of a pointer g (that accepts the address of f as an input) and an int.

This is the error from the compiler:
test_2d.cc: In function ‘int main()’:
test_2d.cc:47:25: error: cannot convert ‘std::vector<std::vector<double> >*’ to ‘double (*)[297680][9]’ for argument ‘1’ to ‘int myfunc(double (*)[297680][9], int)’
return myfunc(&f,count);
^
Here is my code:

#include <iostream>
#include <fstream>
#include <iomanip> //allow setprecision to get all the decimal points
#include <vector>
#include <string>

[Code] ...

View 5 Replies View Related

C++ :: Creating Vector Array And Reading A File

Apr 23, 2013

Creating a Vector Array + Reading a file ....

View 1 Replies View Related

C++ :: Creating (Composite) Vector Array Field?

Jan 3, 2013

In a numerically intensive code, I have a Cartesian vector class Vector3d which has the normal operator overloading and basic functions such as dot product, magnitude, etc. For simplicity, assume that it is not a templated class and its components are of type double.

I frequently need large 1-d arrays (e.g. stl vectors) of Vector3d. Two use-cases must be satisfied:

1) The trivial case in which the data are stored as stl vectors of Vector3d;

2) The more difficult case where the individual components are stored as stl vectors of double, and are not guaranteed to be contiguous in memory (so one cannot rely on "stride").

Assuming the array lengths are all identical, I'd like to be able to access both types in a single loop. The straightforward way for case 2) is to construct a temporary Vector3d from the three components (indexed with the loop index). However, I would prefer not to incur the overhead of the constructor.

Is it possible using template metaprogramming. Ideally I'd like a CompositeVector3d that inherits from Vector3d and is constructed with the component vectors, but can be dereferenced using the loop index in the same way as one would do with case 1.

I am not looking for the typical template metaprogramming utility of being able to operate on the entire array without explicit loops. I just want the syntactic "sugar" whereby CompositeVector3d and Vector3d act the same, plus the avoidance of the cost of the constructor. I am not averse to using an additional templated class (perhaps a Field or a View class) to access the basic storage in both case.

Is it possible to do this without using a full template metaprogramming utility?

View 1 Replies View Related







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