C :: Creating Two Dimensional String - Adding Char

Aug 15, 2014

I am making a program that formats a string. I want to create a new 2 dimensional string that will have many other chars and strings in it beside the original string. Then I split the string up on the newlines and return it. Adding different parts to the 2d string e.g. I need to add five _ as chars not string then I need to add different things. First I use sprintf () to add as much as possible. And then I do what to add the rest?

View 13 Replies


ADVERTISEMENT

C++ :: Creating String Representation Of Unsigned Char Bits

Mar 5, 2014

I need to convert the bit representation of an unsigned char into a string.

so like 254 would be "11111111"

I'm having some trouble where no matter what number I try to convert I get 01111111.

string bin2string(unsigned char N) {
string sN(8,'0');
unsigned char X;
unsigned char Y = 0;
for(int i = 0; i < 8; i++){

[Code] ....

View 4 Replies View Related

C++ :: Adding Up Elements Of Two Dimensional Array?

Jan 9, 2015

This code shows a loop inside a loop initializing a two-dimensional array named arr with elements [2] and [5]. Here's my code:

Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()

[Code]....

Now, what I wanted to do is to have an output showing the sums of each elements. Example, the above code has an output of:

1 2 3 4 5
6 7 8 9 10

I wanted to have more codes which would add up the elements 1 + 6, 2 + 7, 3 + 8, 4 + 9, 5 + 10 and produce and output:

7 9 11 13 15

View 8 Replies View Related

C++ :: Adding-up Elements Of Two-Dimensional Array?

Jan 9, 2015

I would just like to share my code and wanted to do something about it. This code shows a loop inside a loop initializing a two-dimensional array named arr with elements [2] and [5]. Here's my code:

#include <iostream>
#include <conio.h>
using namespace std;

[Code]....

Now, what I wanted to do is to have an output showing the sums of each elements. Example, the above code has an output of:

1 2 3 4 5
6 7 8 9 10

I wanted to have more codes which would add up the elements 1 + 6, 2 + 7, 3 + 8, 4 + 9, 5 + 10 and produce and output:

7 9 11 13 15

View 5 Replies View Related

C++ :: Creating 2 Dimensional Console Base Game

Jun 13, 2013

what i got so for my code.

#include <iostream>
#include <windows.h>
using namespace System;
using namespace std;
int refreshDisplay(int , int);
const char wHole = '@';

[code]....

count <<" The oblective of the game is for the player to move around a 2 dimensional playing field and capture the star withought falling into a black hole or walking off the edge of the playing field. The controls are W = up S= down A=Left D=Right" <<endl; how implement 3 black hole X characters and 2 wormhole characters on field @ and a star *. all these char has to be randomly generated.

View 1 Replies View Related

C/C++ :: Creating Two Dimensional Terminal Based Game?

Apr 4, 2014

i am working on class project in which i have to save the tank from canon....imy tank is moving only when i press the moving key.. and after that i see blank screen what should i do to run my process when i am not pressing moving keys....

View 8 Replies View Related

C++ :: Creating Crystal Lattice - 3 Dimensional Arrays

Apr 14, 2013

I receive unexpected outcome in my program. Instead of getting all combinations of 0, 1, 2 (i.e. 000, 001, ..., 222) I get only 000 001 002 010 011 012. The idea of the progarm is to create a crystal lattice. Each atom of the lattice has 3 coordinates (x, y, z). That's why I create class Atom. Then I create 3-dim array of the type derived from class Atom. Now each element of the class will represent an atom.

Code:
#include <iostream>
using namespace std;
class Atom {
public:
float x, y, z;

[Code] .....

View 2 Replies View Related

C++ :: Char - Adding ABCs (letters)?

Mar 12, 2014

How I can go back to an alphabet letter I want that letter to land on? Adding capital letters. Lower case letters not needed.

For example;
- User enters "XYZ"
- Program comes up with the next 10 letters which would be something like 'HIJ' (Since X+10 = H, Y+10 = I, Z+10=J)

My problem is with the last few letters. The program goes to the next 10 characters ahead of those characters rather then the alphabet.

Program example: (What I want shown)
"What are your three favorite letters?" XYZ
"The next ten letters are: HIJ"

Error example: {It goes to the next 10 characters instead of the next 10 alphabet letters.)
"What are your three favorite letters?" XYZ
"The next ten letters are: ^[a"

Code example: (I've tried other ways as well.)

char a, b, c;
cout << "What are your three favorite letters?";
cin >> a >> b >> c;
cout << "The next ten letters are: " << a+10 << b+10 << c+10 << endl;

View 4 Replies View Related

C++ :: Adding Char Array With Macro?

Dec 30, 2013

The book uses this example:

#define ALLOCSIZE 10000 /* size of available space */
static char allocbuf[ALLOCSIZE]; /* storage for alloc */
static char *allocp = allocbuf; /* next free position */
char *alloc(int n)
/* return pointer to n characters */

[Code] ....

The logic here I don't understand:

if (allocbuf + ALLOCSIZE - allocp >= n)

allocbuf is a char array allocated with 10000 positions. We add that to ALLOCSIZE macro which is 10000. Does that return a value of 20000? If so, it doesn't make sense to do this because all we had to do was this:

if (allocbuf - allocp >= n)

That takes length of allocbuf which is 10000 and subtracts allocp from it. So if allocp is 1000 we are left with 9000 available slots. And we can use that to check if we have enough to allocate n elements.

View 5 Replies View Related

C :: Handling Strings In 2 Dimensional Arrays / Multilingual String Organization

Jan 9, 2015

I have a firmware application that works well where I display simple text messages on an LCD screen. At the moment, the User Interface is only in English and I have the text strings simply declared as follows:

Code:
static char msg1[] = " Welcome ";
static char msg2[] = " Data Read ";
//etc...

I want to add a variable that can set the language dynamically from an external device, and so I thought I could do the following:

Code:
#define ENG 0
#define FRE 1
#define GER 2
//...
static char msg1[ENG][] = " Welcome ";
static char msg2[ENG][] = " Data Read ";

[Code] .....

writeLCD(msg1[cLang][]); When I try to compile the above I get a compiler error at the "static char msg..." declarations. The error is: "error: array type has incomplete element type"

Is this method valid, but I have a simple syntax problem with the arrray declarations? Or is this method unworkable and I should find a different method?

View 6 Replies View Related

C# :: Adding To A String List

Feb 25, 2014

So I have this code:

temp =count + " x " + name;
if (count > 0) { Stats.Inventory.Add(temp); }

Where Inventory is declared as

public static List<String> Inventory, Sellables;

and temp and count are declared locally as

double count = 0;
string name = string.Empty,temp = string.Empty;

An it throws an error

>Craft.exe!Craft.Stats.InventoryUpdate(string NewInventory) Line 166 + 0x73 bytesC#

My main questions is why? This is my first time using lists

View 14 Replies View Related

C++ :: Adding New String Automatically For Each Name

Sep 17, 2012

Im doing a little game, casting dices etc. The problem is that the program will ask for player 1 then if i enter a name and enter it will ask for player two and so going on until i just press enter with a empty field and then continue the game.

The problem is i don't have any clue what code bits to start studying and how i shall lay it up, feels like i need a new string declaration automatically for each name.

View 5 Replies View Related

C++ :: Adding Current Date To The End Of A String

Dec 12, 2014

I need to add the current date to the end of a string but I only need to add the day and not the year or month.

Put the code This is what i have

char date[9];
_strdate(date);
cout << date << endl;

View 1 Replies View Related

C++ :: Adding String But It Return Some Integer Value

Jun 10, 2013

string str = "sfsdfsd"

and i want to add like str[3]+str[4]

but it return some integer value

View 3 Replies View Related

C++ :: Adding New Options To String Class

Oct 8, 2014

I'm giving the replace option to my string:

void replace(string oldstring, string newstring) {
int stroldstringpos=b.find(oldstring);
b.replace(stroldstringpos,newstring.length(),newstring);
}

i have 1 error in these function that i'm confused. imagine the newstring size is more big than the oldstring, how can change the string, but only change the oldstring and add what left?
see these:

String test="hi hello world";
test.replace("hi","hello");

the result must be:

hello hello world

how can i change the replace function for it?

View 3 Replies View Related

C++ :: Count String In A String Using Datatype Char

Dec 20, 2014

I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:

Code:

#include <iostream>
#include <conio.h>
using namespace std;
int main ()

[Code] ....

View 6 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

Apr 20, 2013

I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.

// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);

[Code] ....

View 3 Replies View Related

C++ :: String Class That Finds A Char In String?

Feb 5, 2013

A string class that finds a char in the string?

View 1 Replies View Related

C++ :: Concatenate Two 2-dimensional Int Arrays Into One Larger 3-dimensional Array

Jul 31, 2013

How can I concatenate two 2-dimensional int arrays into one larger 3-dimensional array. This question is also valid for the 3-dimensional vectors. I know the command for the one dimensional vector as:

std::vector<int> results;
results.reserve(arr1.size() + arr2.size());
results.insert(results.end(), arr1.begin(), arr1.end());
results.insert(results.end(), arr2.begin(), arr2.end());

and for the one dimensional array as:

int * result = new int[size1 + size2];
copy(arr1, arr1 + size1, result);
copy(arr2, arr2 + size2, result + size1);

But I do not know how to make a 3-dimensional array or vector.

View 3 Replies View Related

C :: Creating Dynamic String?

Mar 6, 2015

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
char * form(char *format, ...);
}

[code]...

So, this is the code i have problem with, as far as i can see, function form actually does the same thing that printf does.It probably puts all of the arguments sent to the function together into one string.

View 4 Replies View Related

C++ :: Creating A Class Variable With A String?

May 12, 2013

I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:

cajun/mustard

I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:

Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;

Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.

My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.

(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)

View 6 Replies View Related

C++ :: Creating Inventory - Array With More Than 1 String?

Jul 14, 2014

How would i do this? Im trying to create an inventory but this just will not work, when i do it how i have it originally (as shown below):

cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y') {
cout << endl;
string invintory2[6] =

[Code] ....

the program outputs this:

cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y'){
cout << endl;
string invintory1[6];
[Code] ....

however programing it like this seems very... time consuming.

my other arrays (normal ones that just hold a set of int's) look like this:

int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};

Is there any way to do a string array in this way?

View 8 Replies View Related

C++ :: Creating Files With String Filenames?

Feb 22, 2014

I can't get c++ compilers to create or open files with a string input, even though the compiler accepts a file name in "quotes". How can I get this compiled (I am downloading a series of file names which I need to load into a consolidated file).

My coding (the commented line works, the string example does not).

//indirect file open example
#include <iostream>
#include <fstream>
#include <string>

[Code].....

View 4 Replies View Related

C++ :: Creating A Function To Return A String

Aug 13, 2014

I need a function to return a string

I need to pass input as "a,b,c,a,c,d,e"

function should return out put as

"a,b,c,d,e"

View 2 Replies View Related

C :: Creating Program That Can Pick Words In A String Or Array

Apr 24, 2013

Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.

In a sentence like this:
Size= 70
$--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh

The program must capture the $--GGA string then extract from this string:

1) hhmmss.ss
2) IIII.II
3) a (if a = to N or S replace N or S with + or - respectively )
4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )

Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.

View 7 Replies View Related

C++ :: Converting One-dimensional To Two-dimensional Array

Jan 17, 2014

I had a hard question in my C++ final exam and I'm trying to solve it for the last 3 days. I haven't succeded yet! Here is the question: You have a one-dimensional array A[20]={1,2,3,4,...,20} and B[5][4] you have to assign the A array's elements to the B array but there is an order which is: B[5][4] = { { 12, 9, 11, 10 }, { 14, 7, 13, 8 }, { 16, 5, 15, 6 }, { 18, 3, 17, 4 }, { 20, 1, 19, 2 } } and there is a restriction: you can only use ONE for statement, nothing else!

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int A[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20 }; // define A array's elements.
int B[5][4] = { 0 }, k = 1; // define B array and k counter.

[code]....

I can't narrow the statements to one,This program works perfectly but it shouldn't be that long, we need ONLY ONE FOR statement, not two!

View 2 Replies View Related







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