C++ :: Writing Strings Into Array Index Within A Function?

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

Code:
#include<iostream>
#include<string>
using namespace std;
void viewMonth (string month[], int num);
void dayNote (string month[]);
int main()

[Code].....

View 1 Replies


ADVERTISEMENT

C/C++ :: Writing Strings Into Array Index Using Function

Apr 11, 2014

I'm trying to make a calendar and I don't know how to cin strings into an array's index inside a function.

This is my current program.

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

void viewMonth (string month[], int num);
void dayNote (string month[]);

[Code] .....

How do I make void dayNote function work so I can cin a string into the desired array index?

View 3 Replies View Related

C++ :: Print Stars Function - Corresponding To Array Index Size

Nov 24, 2014

I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:

#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);

[Code] ...

View 3 Replies View Related

C++ :: Function To Determine Largest Value In Array And Then Outputs Value And Index

Dec 5, 2013

I'm trying to create a function that determines the largest value in the array and then outputs the value and index. I want to values in the array to be random so I tried using the rand function, although I'm not sure where I'm supposed to put it. My main problem (I think) is outputting the correct values...

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void lastLargestIndex (int numbers[], int arraySize);
int main(int argc, char** argv) {
int number, arraySize = 50;

[Code] ....

View 2 Replies View Related

C :: Write A Function That Finds Integer In Array And Returns Its Corresponding Index

Mar 20, 2013

I have an assignment which requires me to do the following:

Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:

- The first parameter is the array to be searched
- The second parameter is the integer to be found within the array
- The third parameter is the size of the array
- The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.

Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)

Code:

#include <stdio.h>
#define SIZE 10
size_t findNumber(int *sort, const int array[],int key,size_t size);
int main(void){
int a[SIZE];
size_t x;

[code].....

View 1 Replies View Related

Visual C++ :: Writing A Function That Sort Elements Of Array In Numerical Order?

Oct 17, 2014

I have to write a function called sortMe that sorts the elements of an array in numerical order from highest to lowest values (descending order) or vice versa (ascending order).

The assignment asks to: NOT re-arrange elements in the array; instead, it uses a second array, an array of indexes for the elements in the original array and then sortMe sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes.

Header of the function sortMe must be as shown below:

void sortMe(int array[],int sortedIndexes [], int size, char mode)

When mode is 'a', the function sorts the array in the ascending order, and when mode is 'd', the function sorts it in the descending order.

Declare and initialize the array array.

Declare the array sortedIndexes but do not initialize it. You are going to play with the array sortedIndexes in the function sortMe.

EXAMPLE:

int array[5]={3, 5,-1,10,0};
int sortedIndexes[5];
sortMe(array,sortedIndexes, 5, 'a');

After the function call, the elements of the array sortedIndexes should be: 2,4,0,1,3.

notice that the function does not e-arrange the elements in the array.

Code:
#include <iostream>
using namespace std;
void sortMe(int[], int, char);
void main() {
int arr[6] = { 14, -5, 5, 0, 22, -99 };

[code]...

how to use the other array.

View 5 Replies View Related

C :: 2D Array With 108 Strings - Shuffle Function?

Sep 7, 2013

I have a 2D array with 108 strings. How do I shuffle it correctly?

Code:
void Shuffle( char dest[208][13] )
{
// Initialize variables
char temp[13];

// Loop and shuffle(swap array values)

[Code] .....

The program force closes.

View 6 Replies View Related

C :: Concatenate Strings In Array (2D) - Function Not Working Right?

Sep 6, 2013

I have a function that concatenate the strings in an array(2D)

Ex 1: Sean Connery Micheal King James Wood

Result: SeanConnery MichealKing JamesWood ...

The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this

Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..

It adds to first name. Why?

Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()

[Code] .....

View 4 Replies View Related

C/C++ :: Take Values From One Array And Searches For Their Index Position In Another Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array (linear search algorithm). This is an example of the issue im having(its not part of the actual code below)

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2.

for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "";

[Code] .....

View 4 Replies View Related

C++ :: Function Index That Converts Int From 0 To 5 Into Its Word

Apr 9, 2013

Task: - Write a function `index` that converts an int from 0 to 5 into its word. (It should take an int and return a string.)

0 -> "zero"
1 -> "one"
2 -> "two"
3 -> "three"
4 -> "four"
5 -> "five"
anything else -> "other"

#include <iostream>
using namespace std;
string index(int x) {
if(x=0)
return "zero ";
else if(x==1)

[Code] .....

It compiles but doesn't print anything.

View 4 Replies View Related

C :: Array Out Of Index

Apr 17, 2014

I was trying to debug a code which was behaving in an abnormal way

Code:

#define NOOFELEMENTS 32
unsigned char array[NOOFELEMENTS];
unsigned char array1[23];
init() {
for(i=0;i<=32;i++)
{
array[NOOFELEMENTS] = 0
}
}

I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.

View 4 Replies View Related

C :: Calloc For Array Of Array With Negative Index

Oct 14, 2014

I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x].

So i see the array's rows lets say from -20 to dim_y + 20 but a user sees only from 0 to dim_y.

First i had global and already defined the dimensions dim_x, dim_y, so i had this:

Code:

int map_boundaries[dim_y + 40][dim_x + 40];
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20]; In fact, 'map' points to 'map_boundaries' , map[0][0] is map_boundaries[20][20].

I did what is posted in the second post here: Negative array indexing - Everything2.com

I want 'map' to be global. Until now i had defined the dim_y and dim_x so that worked fine.Now i just need to read from a user the dim_x and dim_y.

Until now i have global

Code: int **map_boundaries;

and then in main i use calloc:

Code:

map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*));
for(i = 0; i < dim_y + 40; i++){
map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int));}

but i dont know how to declare this line now:

Code: int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

View 6 Replies View Related

C/C++ :: Calloc For Array Of Array With Negative Index

Oct 14, 2014

I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x].

So I see the array's rows lets say from -20 to dim_y + 20 but a user sees only from 0 to dim_y.

First I had global and already defined the dimensions dim_x, dim_y, so i had this:

int map_boundaries[dim_y + 40][dim_x + 40];
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

In fact, 'map' points to 'map_boundaries' , map[0][0] is map_boundaries[20][20].

I did what is posted in the second post here: [URL] ....

I want 'map' to be global. Until now i had defined the dim_y and dim_x so that worked fine. Now I just need to read from a user the dim_x and dim_y. Until now i have global

int **map_boundaries;

and then in main i use calloc:

map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*));
for(i = 0; i < dim_y + 40; i++){
map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int));
}

But I dont know how to declare this line now:

int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];

View 3 Replies View Related

C# :: Index Was Outside Bounds Of The Array

May 21, 2014

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mind_Puzzle {
public partial class Form1 : Form

[Code] .....

When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".

The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe

View 1 Replies View Related

C# :: Array Index Management

Oct 27, 2014

I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).

Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].

View 3 Replies View Related

C :: Sorting Elements In 2D Array By Their Index

Jun 17, 2013

I need to sort the elements in a 2d array by their index (starting from 1) for example:

Code:
1 5 3
4 7 8
4 10 2

10 is the biggest element and its index is 32, after 10 comes 8 with index 23 etc etc...

Looking for examples for two orders ... By descending and ascending order...

View 5 Replies View Related

C :: Copy Index Of Characters Of One Array To Another?

Oct 12, 2013

my question is located as a comment beside the last printf ! ? check the comment near the last printf the comment is ==>here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?

Code:
#include <stdio.h>
#define N 30
#define n 100

[Code]....

here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?

View 1 Replies View Related

C++ :: Fixing Array Index Out Of Bounds?

Dec 7, 2014

Design and implement the class myArray that solves the array index out of bound problem, and also allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray is an array of type int. During execution, when accessing an array component, if the index is out of bounds, the program must terminate with an appropriate error message. Consider the following statements:

myArray<int> list(5); // Line 1
myArray<int> myList(2,13); //Line 2
myArray<int> yourList(-5,9); // Line 3

The statement in Line 1 declares list to be an array of 5 components, the component type is int, and the componentst are : list[0], list[1]…list[4]; the statement in Line 2 declares mylist to be an array of 11 components, the component type is int, and the components are: mylist[2],…mylist[12].

This is what I have so far:

#ifndef H_myArray
#define H_myArray
#include <iostream>
using namespace std;
template <class myArray>
class myArray
{
public:
private:
return 0;
};
#endif

View 1 Replies View Related

C/C++ :: Couldn't Find Index Of Array

Feb 12, 2014

I have problem with find the index of the following array.

int minimums[2]={201,201};//first initialize both to greater than maximum allowed

for (int index = 0; index < 200; index++) {
if(find_array[index] < minimums[0]) {
minimums[0] = find_array[index]; //Lowest number

[Code]....

View 14 Replies View Related

C# :: Getting Index Was Outside The Bounds Of The Array Error

Sep 20, 2014

I'm getting "Index was outside the bounds of the array." computerInput.pher[i, 0] = computerInput.availperi[a]; on line 198 but I'm not sure what I need to do in order to correct it. My array seems fine to me and I do see that "i" is showing 0 when debugging and won't change. Either I'm missing something or wrote my array wrong.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestComputerOrder {
class TestComputerOrder {
int style, board, hardDrive;

[Code] .....

View 7 Replies View Related

Visual C++ :: Index Position In Array

Dec 9, 2014

My program takes the values from one array and searches for their index position in another array(linear search algorithm). This is an example of the issue I am having(its not part of the actual code below) :

a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}

If it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2. any thoughts on how to fix this?

Code:
for (int q=0; q=size2;q++) {
int rs=secfunc(array1;size1;array2[q])
if(rs>=0) {
cout<<rs << "
";

[Code] .....

View 12 Replies View Related

C :: How To Concatenate Array Index For Same Elements For Specified Range

Apr 22, 2013

Actually i found some mistakes in my post. So here is the modified version. I want to concatenate the indexes of elements of array that has the same value for specific range.In my case the range is 4

Code:

int element[8]={2,2,0,3,3,0,1,2};
col=4;
int rr;
int qq=0;
for (rr=0; rr<col;rr++){
join_tmp[qq]=rr;
while ((element[rr]== element[rr+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d
",join_tmp[qq]);
rr++;
}
qq++;
}

Code:

//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}

Code: I want input like
10
2
3
Instead i get
10
2
34

how can i fix it so it will only iterate to the specific range?

View 2 Replies View Related

C :: Order Values Of Int Array Only Between Two Index Numbers

Mar 16, 2013

I have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.

An example:
doubles array: (12,44;12,44;7,22; 12,44)
ints array: ( 4 , 2 , 3 , 1 )

now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 4 , 2 , 1 , 1 )

Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:

doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 1 , 2 , 4 , 1 )

How i can order the ints array only between an interval that is given by the interval of numbers that are equals in the doubles array?

View 4 Replies View Related

C++ :: No Check To Determine Whether The Array Index Is Out Of Bound?

Jun 9, 2013

This is an assignment question In C++, there is no check to determine whether the array
index is out of bounds.Design a class myArray that solves the out-of-bound array index problem and allows the user to begin the array index starting at any integer, positive or negative. Every object of type myArray should be an array of type int.

Part 1 processes only int arrays. Redesign the class myArray using class templates so that the class can be used in any application that requires arrays to process data.

I don't understand the second part. should i just change the array from int to char or something?

View 1 Replies View Related

C++ :: Write Index Of Greatest Element Of Array

Oct 29, 2013

Create a program that will ask the user to input 10 integers of an array the program must write the index of the greatest element of the array

target output

input the integers

the greatest element is 5 and the index is 7

View 3 Replies View Related

C :: How To Stop Passing Char Array Index As Pointer

Dec 23, 2013

I am trying to write a light weight printf style function.

I have got this far:

Code:

void println(const char *txData){
LOG(__PRETTY_FUNCTION__);
UARTPuts (LPC_UART0, txData);
}
void miniPrint(const char *format, ...)
{
unsigned int index = 0;
va_list argptr;
va_start(argptr, format);

[Code]....

I understand why I think. When I am passing the reference to the array possion it is outputting everything up to the next /0. So my question is how do I stop it?

I dont have much choice as to how the output wants it:

Code: void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)

Thats library code, so I dont want to change it. I.e I have to pass an address into println.

View 1 Replies View Related







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