C/C++ :: Assigning Symbols To Numbers In 2D Array?

Sep 11, 2014

I'm working on a program in C++ that is supposed to read in a file, store the content of the file into a 2D array, assign characters to each of the numbers in the array and store in a char array, and print both of these arrays. It's then supposed to go through the initial array and make sure that each number doesn't differ in value from it's neighboring numbers by more than 1, correct these errors by replacing these numbers with the value of the average of their neighbors, assign characters to this corrected array as it did before, and print both arrays.

The character assignments go as follows:

0=blank
1=.
2=,
3=_
4=!
5=+
6=*
7=#
8=$
9=&

I have the code written that opens the file and loads the array, but where to go from there. To me the obvious, although probably not best, way to do the assignments is to go through the array with a for loop and use a series of if statements to check for the value of the number at each index and assign the appropriate symbol.

Here is the code I have so far:

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int size = 100, i, j;
prog >> size;
int **numArray = new int* [size];

[code].....

View 2 Replies


ADVERTISEMENT

C/C++ :: Print Rows Of Ascending Numbers And Other Symbols?

Dec 16, 2014

for example having input "12345556asf87" we get "123456asf". I need to do this task with getchar and putchar, and the with strings. My programs aren't working

stream:
char c = 0, c_ = 0;
char flag = 0;
while ((c = getchar()) != '.')
{

[Code]....

View 1 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 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++ :: 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++ :: Assigning String Tokens To Array?

Oct 20, 2014

I need to dynamically build a control file for a SQL loader but when tokenizing line values read from a file i am unable to work/assign the last value to a variable even though i can print the actual token value while in the loop.

Below is the code snippet i have and get:

Code:
//headElement declared as headElement[42]
//getCol function is used to decode column keys present in line being read
istringstream ss(line);

[Code] .....

I've attached a sample file as well.

View 1 Replies View Related

C :: Assigning String To Array And Compare It?

Mar 20, 2013

I have this code :

#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

[Code] ...

And this error occued with me I don't know why ???

myHeader.h:42:19: error: expected ")" before string constant

This code is compiled from file called myHeader.h ...

View 2 Replies View Related

C :: Rotating Array And Assigning It To Different Variables

Feb 3, 2013

I have a problem with rotating an array and assigning it to different variables. This is wat i have done.

Code:

#include<stdio.h>#include<stdlib.h>
#include<conio.h>
#include<math.h>
int n[16],a[16],n1[16],n2[16],n3[16],n4[16],n5[16],n6[16],n7[16],n8[16],n9[16],n10[16],n11[16],n12[16],n13[16],n14[16],n15[16],n16[16], c=0;
int x[16],i,j,k;
int rotate();

[code]....

View 4 Replies View Related

C++ :: Assigning Values To Two Dimensional Array

Feb 18, 2014

I'm trying to write a very simple program that takes values in through variables, and stores those values in a two dimensional array. The values are already passed into the void function, I need to have those values write to their corresponding locations in the array.

void planeSeats(int seats[13][6], int ticket, int ticketRow, int ticketColumn) {
if (ticket = 1) {
if (ticketRow >= 1 && ticketRow <= 2) {

[Code] ....

For example, lets say that ticketrow is 2 and ticket Column is 4 .

What I need is for ticketRow and ticketColumn to assign that data to seat[ticketRow][ticketColumn], turning it into seat[2][4]. How to do that.

View 2 Replies View Related

C++ :: Assigning String Tokens To Array?

Oct 20, 2014

I need to dynamically build a control file for a SQL loader but when tokenizing line values read from a file i am unable to work/assign the last value to a variable even though i can print the actual token value while in the loop.

Below is the code:

//headElement declared as headElement[42]
//getCol function is used to decode column keys present in line being read
istringstream ss(line);
wfile << "LOAD DATA " << endl <<
"INFILE * " << endl <<

[code]....

View 5 Replies View Related

C :: Assigning Array With A Variable Number Of Elements

Jul 18, 2014

I have a simple problem about memory allocation.In the function Nr_elements() i assign a value which represent the elements of array. The pointer p is initialised with the address of variable n, but when i compile i dont know why but dont work. This function return a pointer.

Code:
#include<stdio.h>
#include<stdlib.h>
int *Nr_elements();
int *allocate(int);
void deallocate(int *);
[code]....

View 3 Replies View Related

C++ :: Assigning Prime Number To Element Of Array

Apr 12, 2014

I want to assign prime number to the element of an array.

#include "stdafx.h"
#include <iostream>
#include <conio.h> //For Console Input/Output function like clrscr & getche
using namespace std; //Using the "standard" namespace of iostream class

[Code] ....

View 2 Replies View Related

C++ :: Assigning Colors To Individual Characters In Array?

Aug 31, 2014

Basically I am making a console RPG (isn't every beginner nowadays?) and I am having an incredible amount of trouble assigning specific characters their own color. e.g. monsters being red, cash being green, etc.

I took out Left, Right, and Down controls because of character constraint.

#include <iostream>
#include <windows.h>
//%%%%%%%%%%%%%% COLOR CALL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setcolor(unsigned short color) {
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);

[code]....

View 8 Replies View Related

C++ ::  accessing / Assigning Values Of A 5 Dimensional Array

Feb 8, 2014

I'm okay with 2-dimensional arrays, but when I get to 3 or more, I can't seem to wrap my head around how to assign and/or pull values from specific parts.

To give an example, let's take the following example:

We know that a player can take up to 5 total quests, and each quest can have a max of 5 tasks.

Let's assume I have the following multi-dimensional array holding all of a players quest data:

quests[0] = 78;// Store the questID
quests[0][0] = 3945;// Store the 1st creature ID
quests[0][1] = 2230;// Store the 2nd creature ID
quests[0][2] = 3045;// Store the 3rd creature ID
quests[0][0][0] = 2;// Store how many needed of the 1st creature
quests[0][1][0] = 5;// Store how many needed of the 2nd creature
quests[0][2][0] = 13;// Store how many needed of the 3rd creature

As we know, the above code can't be done. How do I assign certain values to each specific dimension?

View 6 Replies View Related

C/C++ :: Assigning Functions To Array Of Function Pointers

May 13, 2013

I'm trying to create an array of function pointers and then assign compartilbe functions to them, so I can just call *pf[0](xxx);

The functions are all of the type

void func01(unsigned char*, int, int)

how would I create an array of function pointers and assign the address of the functions to them? So I could call them like

ptrToFunction[i](charBuffer, 10, 20);

I've read a bit on line and I thought I could do it but so far I've failed.

It seems trivial and I feel I'm close but close isn't good enough.

I'd like to assign the fuction addresses like this:
for (int i=0; i<10; i++)
if (i==1)
ptrToFunction[i]=func01;
if (i==2)
ptrToFunction[i]=func02;
etc.

The actual logic is somewhat different than this but this close.

View 4 Replies View Related

C :: Reading Values From File To First 2 Columns Of 2D Array / Assigning 0 To 3rd Column

Apr 4, 2014

I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.

I'm not sure for instance why on the bottom loop for line 1 it doesn't print:

temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1

Code:

#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");

[code]....

View 8 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

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++ :: Alt Key Symbols With Code Blocks

Apr 30, 2013

I'm using Code Blocks but for some reason it doesn't process alt symbols. You know... alt symbols are like this: ☺♫↓☻♪♥↕. Code Blocks says that they're "invalid characters". Is there any attatchments or mods so Code Blocks can process them or will changing the settings?

View 1 Replies View Related

C/C++ :: Library Has No Exported Symbols?

Jan 10, 2013

I built a C++ static library using WatCom IDE. It compiles without error, but running WLIB on it produces the msg:

Warning! Library contains no external symbols My WatCom compiler host is windows, & target is DOS.

If I convert the Library to an .exe program, by adding a main(), it executes fine, So there seems to be something I'm missing in the IDE settings for building a .lib.

View 2 Replies View Related

C++ :: How To Output Special Symbols

Jan 30, 2012

For example, how to output "Delta" (like a triangle) in C++?

View 13 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++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

I'm making a program that prints a triangle of @ signs given rows (but not columns).

For example, the output with rows = 4 would be:
@@@@
@@@
@@
@

and rows = 3 would be:
@@@
@@
@

However, trying to make this has given me a program that does something similar (but not the same):

for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@

and rows = 3 gives
@@@
@@
@

It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:

1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.

My current code is:

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;

[Code] ....

I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?

View 4 Replies View Related

C++ :: Function To Check For Symbols In Input

Jun 10, 2013

I need a function to check if the inputted string contains a colon. It has to be in an if loop as the condition.

View 1 Replies View Related

C++ :: How To Ask User To Input Operating Symbols

Aug 6, 2013

how to ask the user to input operating symbols like "+","-","*" and then use it to operate on the numbers. The user should be asked to input the symbols not like this

1.+
2.-
3.*

View 2 Replies View Related







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