C :: Fastest Way Of Changing Elements In Array Of Characters For Encode

Feb 15, 2014

I am wonder what is the fastest way of changing elements in array of characters for encode purpose, here is simple example presenting an idea:

Code:

char *a = "123456789":
char b[] = "ABCDEFGHI";
int 1;
for (i=0;i<strlen(a);i++) {

b[i] = a[i];
}

Is this approach better or worse than bit manipulation ?

View 4 Replies


ADVERTISEMENT

C++ :: Dynamically Changing Array Elements Inside Of Structures?

Feb 1, 2015

I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.

#include <iostream>
#include <cstring>
using namespace std;

[Code]....

View 4 Replies View Related

C++ :: Changing Array Of Characters To A String Array?

Apr 7, 2013

I have an array titled: char TypeOfSong[arraySize] where the array size is 15. I am reading data from a file into this array and the characters can be either 'C', 'D', 'E', or 'R'. Each of these characters stands for a word (sting) and when I output the array, I need the strings to show up, not the characters. I have been reading online and in my book but I can only find information on turning one array with the same characters into a string. How would I go about changing this character array with different characters into a sting?

The characters stand for:

C = Country
D = Dance Party
E = Elevator
R = Rock

View 5 Replies View Related

C :: Changing A Files Lowercase Characters To Uppercase?

May 15, 2014

Have a program prompt the user for a filename to open. Change every alphabetic character in the file to a capital letter. Numbers and special characters should not be changed. Print the output to the screen.

My problem currently is I can't get it to open a file in the same directory as the programs .exe file. I get else statements error message each time.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h> /*for toupper function*/
#define MAXSIZE 1024

[Code].....

View 9 Replies View Related

C :: Fastest Way To Check If Bytes Contained In Array Are All X00

Nov 30, 2014

I'll process the raw content of a stream which obviously will be loaded one chunk at a time into an buffer.I need to check if every chunk content is x00 filled. If it is, I'll increase the blank chunks counter of 1.On your personal opinion, which is the fastest an less cycles consuming manner to achieve such result?

I was wondering this: is it possible to make an instant XOR of all the buffer content to check if it does return 0 ?the only way is it to cycle through all the bytes and compare each one of them with 0?

View 1 Replies View Related

C :: Encode/ Decode Existing EXE File

Dec 28, 2014

Let's say I have an exe-file (for example computer game) and need to forbid to run it until certain date or time during the day. Any 'manipulations' with file are allowed. offer me a simple way of how to encode/decode such a file?

View 7 Replies View Related

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C++ :: Encode / Decode Any Message Based On Given Secret Instructions

Jun 15, 2013

Write a program that will encode/decode any message based on the given secret instructions.

Input
The input shall be composed of 3 parts: A string, maximum length of 255 characters) in a single input line (i.e., terminated by the end-of-line or carriage return) representing the message to be encoded or decoded, A single character identifying the operation to be performed–‘E’ for encode or ‘D’ for decode, and An integer giving the number of columns to be (or that was) used for encoding called the key.

Output
The program shall display the encoded/decoded message. Since the algorithm fails if a sequence of spaces, at least as long as the key, is formed at, and subsequently deleted from, the end of the last column, replace spaces by periods in the output.

Input Validation
None.

Sample Runs

Enter the message: meet me in the park tonight at seven.
(E)ncode or (D)ecode? E
Enter number of columns (key): 5
Encoded message reads: mm.pth.neetaots.e.hrn.e.tiekiav..n..gte.

[Code] ....

View 4 Replies View Related

C/C++ :: Check For Set Of Characters In Array Of Characters?

Mar 26, 2014

I have an array of characters. I am trying to find "houston". The only way I can think of to do this is to use a for loop and check each individual character. Is there an easier way to do this?

char string[] = "Fishing tourism miami atlanta dallas houston";

View 9 Replies View Related

C++ :: Fastest Way To Calculate Fibonacci

Apr 1, 2013

What is the most efficient way to calculate Fibonacci. Is it recursion with memorization, is it iteration or is there another approach?

View 1 Replies View Related

C/C++ :: Fastest / Most Efficient Way To Add Two Fractions

Jul 12, 2012

I have to write a function

struct rNumber add(rNumber a ,rNumber b); 

which adds two rational numbers in following representation :
rNumber := s*(n/d)* 2^e
struct rNumber{
 _byte_t s; // sign (do not consider for this question)
 uint n; //numerator
 uint d;// denominator
 short e;//exponent
}  

If the exponents of both numbers are not equal, then they have to be made equal in order to add them. This can be made in 4 ways : increase or decrease the n or d of both numbers.

But if we decrease the denominator of a number (a.d =1) by shifting it for example 1 bit to the right, we get 0 which leads to INFINITY for the fraction. In another case decreasing the numerator would lead the n to be 0 which meanse the whole fraction is then 0.

According to this, in worst case, all 4 cases has to be checked for the right result.

So far the UNDERFLOW of n or d is considered. If we try to increase the value of n or d, then OVERFLOW may also occur.

The very first, intuitive solution would be iteratively increase/decrease one of the terms and to check if the change leads to ZERO or INFINITY.

View 5 Replies View Related

C++ :: Fastest Way Of Passing Data To A Class

Apr 25, 2013

I'm currently building a new data structures that will be used in monte carlo generators (and so will be constructed several million times) and I'm wondering what's the best way (computer-speed-wise) to pass the data to the constructor. I am currently doing it using references and passing arrays as pointers like this:

Code:
class particle{
public:
particle(double *ar,int &id):IDup(id){
for (int i=0;i<5;++i)
Pup[i]=ar[i];
}
int IDup;
double Pup[5];
};

I'm assuming that since using references has no need to create a temporary memory slot it's more efficient .....

As for the arrays: is there a way for me to pass them as reference as well? (not using c++11), I'm using arrays instead of vectors as much as I can because I assume that vectors, being more advanced data structures, would take more time to create.

View 14 Replies View Related

C++ :: Changing Array Values

Jun 15, 2013

If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?

#include <iostream>
#include <math.h>
#include<iomanip>
#include <vector>
using namespace std;

[code]...

View 7 Replies View Related

C++ :: Absolute Fastest Container To Lookup Names

Jan 9, 2013

Names are std::string no more than 3 characters in length. What built in container or boost container is fastest at finding a name (Key) in it's container.

Finding a name.
At the name will be a value double.

I need the most efficient at finding and finding/updating the value. Forget out inserts and deletes.

View 2 Replies View Related

C :: In Two Dimensional Array 0,0 Spot Keeps Changing

Jan 12, 2015

I have a 10x10 array, initialized to all zeros. I create 2 random numbers for the purpose of guessing a position in the array.
However, when I print the array, the 0,0 spot keeps shifting to match the 2nd random number generated. Is there something strange about the 0,0 spot?

Here is my code:

Code:
seedrnd();
for (x=0;x<2;x++) {
randArray[x]=rnd(10);
}
for (x=0;x<2;x=x+1)

[Code] .....

The 2nd to last print statement actually prints randColumn. The last print statement correctly prints 0.

View 7 Replies View Related

C :: Changing Order Of Numbers In Array

Dec 10, 2014

I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:

1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.

2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.

Here is my code:

Code:

// ConsoleApplication3.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
int a[10], i, n;
int pom;
do {
printf("number of elements in an array a: n = ");

[Code]...

View 5 Replies View Related

C++ :: Macro For Changing Array Size

Nov 22, 2013

I'm trying building a new macro for change the array size:

#define redim(varname,x) ((sizeof(varname)*) realloc (varname, x * sizeof(varname)));
int b;
redim(b,3);

error message:
"error: expected primary-expression before ')' token"

what isn't right with these macro?

View 10 Replies View Related

C++ :: Fastest Comparison Algorithm Based On A Predefined Container?

Sep 3, 2014

Suppose you have defined a container of elements and you want do define a comparison function between elements based on the ordering of the elements in that container. What algorithm for the comparison would be the most efficient?

Example:
master = {tom, sam, mary, sally, bert, frank}
subset = {bert, sam, mary, tom}
goal: change subset to {tom, sam, mary, bert}

My current idea is to simply iterate from the beginning of the container, and whichever of the two elements is found first is the lesser (assuming the second is not the same as the first). It seems kind of naïve though. Any better performing algorithm? This is what I have so far:

#include <iostream>
#include <iterator>
#include <list>
#include <vector>
#include <stdexcept>
#include <algorithm>

[code]....

Would perhaps forcing the container to have a random access iterator, like vector, and then writing a specialized comparison function based on that perform even faster? Or perhaps force the container to be a map to integers, and compare the elements by comparing the integer mapped values?

View 19 Replies View Related

C++ :: Values Are Changing When Passing Arrays And Array Sizes?

Feb 28, 2014

I'm working on a homework assignment that asks me to roll two die a user given number of times, find the roll sums, and a few other things. I'm working on it one module at a time and I'm running into two big problems so far.

The first problem is that my int variable rolls changes to a number within the random number generator range of numbers after I run rolldie. I got around this by making a const equal to the user entered value of rolls just so that I could continue developing the program.

My second problem is that the values of the arrays resultsOne[] and resultsTwo[] are changed after running findsum(). Why this is happening and I even tried passing them as const, but that changed nothing. We just started learning about passing arrays to functions, so there might be something big that I'm missing.

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void rolldie(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo);
void findsum(int resultsOne[], int sizeOfresultsOne, int resultsTwo[], int sizeOfresultsTwo, int tossSums[], int sizeOftossSums);

[Code] ....

View 8 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++ :: Write Function That Takes Array And Returns True If All Elements In Array Are Positive

Jan 21, 2013

Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.

View 6 Replies View Related

C++ :: Using Loop To Process Array Of Characters Starting From Beginning Of Array?

May 3, 2014

Assume you want to use a loop to process an array of characters starting from the beginning of the array. You want the loop to stop when you read the null terminator character from the array. Fill in the loop test condition that will make this work correctly.

index = 0;
ch = array[index];
while ( _____________________________)
{
// process the character
index++;
ch = array[index];
}

View 1 Replies View Related

C++ :: Assigning Elements Of 1-D Integer Array Into 2-D Array Of Integers

Sep 27, 2013

I am having problem in writing the code for the problem "To assign the elements of 1-D integer array into 2-D array of integers such as if the array is 1,2,3,4,5,6 The resultant 2-D array should be like :

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

View 7 Replies View Related

C/C++ :: Testing Character Array Against Array Of Characters?

Apr 16, 2014

I am currently having an issue with validating user input for a state abbreviation. I have an array where a list of abbreviations is stored to use as a comparison for whatever the user inputs. I have been able to get the list loaded properly but whenever i go to compare, it always comes back as true even if it isn't. Here is some relevant code:

static char stateTable[STATE_TABLE_SIZE][STATE_SIZE];
int main() {
char buffer[40], *testCustName[40], testState[5], testCode;
buffer[0] = '';
int quit = 0;
int p = 0;

[code].....

View 6 Replies View Related

C/C++ :: Difference In Array Name And Address Of First Elements Of Array

Aug 13, 2014

I have just started learning C language, I have read that array name is the pointer to the first element of array.

So,technically both a and a[0] should have different memory address and a should hold address of a[0],

But when I declare an array and print the address:

int a[5]={2,4,6,8,10};
printf("The address of a and a[0] are &d and %d",&a,&a[0]);
Output is: The address of a and a[0] are 2358832 and 2358832

Why I am getting the same result, shouldn't I be getting different memory address for both a and a[0].

View 2 Replies View Related

C/C++ :: How To Initialize Array Of Pointers To Array Of Characters

May 21, 2014

I am trying to initialize an array of pointers to an array of characters, I can do it in 3 lines but I really want to do it in one line at the same time keeping the #define.

3 lines initialization (can compile)
======================
#define A 1
#define B 2
char row1[] = {A|B, B, A};
char row2[] = {B, A};
char *test[]= {row1, row2};

1 line initialization (failed)
===============================
char *test[] = { {A|B, B, A}, {B, A} }; // <- how do i do this??

I do not want this because it waste ROM space
=============================================
char test[][3] = { {A|B, B, A}, {B, A} };

View 18 Replies View Related







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