C :: How To Create Array Of Arrays
Nov 3, 2014
I wanted to do this: Accept a line of input from user and save it to an array1 and copy its contents to other array in a set of arrays and then input another line to array1 and then copy it to next array in the same set and so on.... I know it is confusing but I can put it like that I want to create an array of arrays (Set of arrays). How can I do so?
I wrote a code to input the line in an array and tried to copy it another array of pointers, but pointers are just addresses so the same adress is copied again and again so, all the pointers of the array point to one address only. The code doesn't print anything when I try to print all the lines that were saved.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXLEN 1000
#define MAXSIZE 100
int getline(char [], int );
void storage(char line[]);
[Code] .....
View 2 Replies
ADVERTISEMENT
Jun 12, 2013
how to create functions with arrays :/
You have to write a single C program that creates a one dimensional array of size MAX(to be declared as a declarative constant using directive #define MAX 10), initializes its elements with a given value using the function InitArray, then populate the array with some random numbers between 1 and MAX inclusive, and finally search the array for certain keys.
The structure for this C program is as follows:
int main() {
//array A to be locally declared here
int
size = MAX;
}
[code]....
View 3 Replies
View Related
Feb 21, 2015
Create a payroll program to store and calculate the payroll for a small company with a maximum of 20 employees.
Program parameters are as follows:
1. Create a menu with the following options (use a do-while loop):
A or a to add employee info
D or d to display employee info
T or t to display total payroll
S or s to display the info of all employees
Z or z to exit program
The information for each employee is: employee number, hours worked, pay rate per hour, tax deduction.
2. Use an array of doubles to store employee information.
3. Menu option A or a: ask the user for the employee information one value at . a time and store it in the array.
Please enter employee number: 2190
Please enter hours worked: 32.50
Please enter pay rate: 9.25
Please enter tax rate deduction: 5.50
4. Option D or d: ask the user for an employee number as integer and display . the information for the corresponding employee (cast the employee number
. in the array to integer and then compare). If employee number does not . match, output a msg. indicating "no such employee". If the employee number . is a match, output all the employee information stored in addition to the . calculated deduction and salary.
Output sample:
Info for employee number: 2190
Hours worked: 32.50
Pay rate: $ 9.25
Tax deduction: 5.50 %
Total pay: $ 284.89
5. Option T or t: calculate and output the sum of the total pay of all
. employees.
6. Option S or s: display the information for all employees in the same
. format as in option B.
7. Option Z or z: exit the program.
#include <stdio.h>
#define MAX [20]
int main(void) {
int i;
for (i=0;i<=20;i++) {
char MenuOption=0;
int EmployeeNumber;
[Code] .....
View 1 Replies
View Related
Oct 26, 2013
I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.
Code:
* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}
[code]....
View 7 Replies
View Related
Apr 23, 2014
I cant get with part of it is wrong, i want to sum every row, too.
// Color Number.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<conio.h>
#include<iostream>
[Code].....
View 1 Replies
View Related
Jun 25, 2013
This program needs to display a vertical graph of asterisks showing production for each plant in the company ...
Here is what I have so far:
***********************************
This program will read data and
display a vertical graph showing
productivity for each plant.
Reference Display 7.8 pg. 401-3
***********************************
*/
#include <iostream>
[Code].....
View 1 Replies
View Related
Feb 9, 2014
I'm trying to create a function that uses dynamic allocated arrays instead of vectors because I want to see how they work. Basically, this function asks the user to input how many people they are going to enter followed by their name; then, they enter how many of these people want to register for an ID followed by their phone #.
For example:
"How many customers will you like to enter? " 3 //user inputs 3
Bob Allen //user input
Ellen Michaels //user input
Jane Andrews //user input
[Code].....
View 1 Replies
View Related
Nov 24, 2014
I got this program to create an array of playing cards and assign the values and suits and shuffle the array. I'm at the point where I need to output the cards but I need to burn the first card by making it output "**" instead of the card. my cards[] is a constant so I can's assign the first card as such.
void showCards(const int cards[], int numCards, bool hideFirstCard) {
if (cards[0]) {
hideFirstCard=true;
cards[0] = '**';
} for(int a = 0; a <= numCards; a++) {
cout >> showCard(cards[a]);
} }
View 1 Replies
View Related
Dec 1, 2013
I am trying to create a box outside my 9x9 array. However, my box did not cover up everything.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#define row 19
#define col 19
[Code] ....
View 6 Replies
View Related
Jun 7, 2014
I need addition array1 array2 in new array before I make this program but the values of array1 and array2 there are in code c# that is worked without problem.
But now i need the user enter the values of arrays, i make that but i failed in addition array1 and array2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyArray {
[Code] .....
View 1 Replies
View Related
Oct 12, 2014
I am trying to generate two arrays from one big array, of which the sum of the 2 array's elements are as close to equal or equal to each other if possible, or one array summed up minus the second array summed up will be as close to zero as possible. I start with int array of 30.
It says that the lowest possible combination of one array minus the other is 239 which I know is not true. Also this needs to run in under ten minutes.
#include <iostream>
using namespace std;
const int size = 30;
[Code]....
View 4 Replies
View Related
Feb 10, 2015
I am trying to see if I can create an array of nodes. I think I have it down somewhat but this is what I have.
Code:
#include <iostream>
using namespace std;
/*This is a template of a person....sorta*/
class person{
public:
int data[32];
bool selected = false;
person(){
[Code]...
I am trying to see if there is a way for me to create a 86 slot array of person nodes. I am not sure how to do it and how to access them afterwards. I know that I am creating the bitstring of person correctly but I am not sure how to get the array of person going.
View 7 Replies
View Related
Dec 19, 2014
Is it possible to create an 8 dimensional array in C? If no, then what can I do to improvise or let say bypass the limit?
View 7 Replies
View Related
Feb 14, 2013
What I am trying to do is to have the program create 2D array that for each row, no two numbers are the same and only consists numbers between 1-9. The array lists out every possible combinations. Supposely I do not know the number of possible combinations, I had it keep adding new rows until there are no more possiblities left.
The problem with my code is when I print out the completed array, it gives out really, really large numbers. But when I print the array from inside the first loop, it gives correct values. I do not know exactly what happened.
Code:
#include <stdio.h>
int main(void) {
int double_digit[1][2];
int a = 1;
int b = 1;
[Code] ....
View 5 Replies
View Related
Oct 15, 2014
I have to create dynamic array, where each element of it points to some value. I know how to create dynamic array
Code: array_record * record_1 = (array_record*)malloc( (group!/(2!(group!-2)!)) *sizeof(array_record));
But i don't know how i create this case. for example what i want if array elements are:
Code:
index value value
0 01 -> 345
1 02 -> 457
2 03 -> 689
3 21 -> 634
so if i have value somewhere 01 match with 01 in this array it display 345. how i can implement it?
View 1 Replies
View Related
Sep 16, 2014
My assignment is use a 3D array to create an image. Use an array of the form arr[300][200][3]. For this homework, you need to use an array of the form arr[3][400][500]. It will have 400 rows and 500 columns. You need to first initialize the array as described in class and after that write the array to a ppm image file. When viewed using Gimp, it should display USM. The letters would be 200 pixels high and 100 pixels wide each. Use at least 15 pixels for the width of the stroke. Use different colors for each letter and a different color for the background.This is what I have so far.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void initialize(unsigned char a[][200][3], int nrows, int ncols, int nc);
void printAll(unsigned char a[][200][3], int nrows, int ncols, int nc);
[code]....
View 3 Replies
View Related
Apr 24, 2013
I want to create 4 dimensional array, in that first three dimenstional are fixed size and the final index will be on 0 to N-numbers.
E.g., double array[500][25][10][<NOT FIXED>].. So I cant create statically, because the index size are more. Also I have tried 4 dimenstional vector, but its giving 2 problem.
(i) I am storing 4th dimenstion size is more than vector[0][0][0].max_size()
(ii) Storing and Retrieving its more time in vector
So, any other solution to store large array which is 3 index is FIXED and final one is not FIXED?
View 16 Replies
View Related
Jan 16, 2015
I am trying to do this:
Read a text file which is like:
2
2 10 1 2 7
3 8 3 7 7 10 7
The first line indicates how many paths exist in my design.
The second and third lines are those lines(the first number indicates 2 pairs, so 10,1 and 2,7 are 2 pairs)
The first element in the third line indicates 3 pairs and the pairs are 8,3 and 7,7 and 10,7.
I have been able to read the text file and store these into ONE array. However, I need to divide them up and have each line in a seperate array.
So for example
array alpha to contain 10,1 and 2,7
array beta to contain 8,3 and 7,7, and 10,7
How would you do this?
View 4 Replies
View Related
Sep 23, 2014
m_sName-- character array shall be 128 bytes
How do i create a character array that has 128 bytes?
View 1 Replies
View Related
Jan 2, 2013
I am trying to create an array with the size of the first value of one file wich is the same of the first line because the first line only have one value. Here is how i am trying to do it ...
FILE * fich;
int test;
fich=fopen(nome_ficheiro,"r");
fscanf_s(fich,"%d",&test);
int np=test;
No*aux=primeiro;
[Code] .....
View 3 Replies
View Related
Mar 21, 2013
how to correctly use realloc on an array of char arrays? Say I want to store strings in arrays (=array of char arrays) and double the size of max. strings (y value):
Code:
int x=200;
int y=10;
char *carray[y];
for (int j = 0; j < y; ++j)
carray [j] = malloc (sizeof(char)*x);}
}
[code]...
fix the realloc part of my code?
View 2 Replies
View Related
Jan 29, 2015
I am wondering how I could make an array which contains arrays, but with a variable size.My first try..
Code:
int array[][] = {{1}, {2}};
But this isn't proper
View 2 Replies
View Related
Mar 9, 2013
I have same question as posted by holla and Iam not sure about merging the contents of 2 sorted arrays into another array without duplication of values.
View 9 Replies
View Related
Jan 11, 2014
Place the even lucky numbers in an array called evenList, the odd lucky numbers in an array called oddList, and the negative lucky numbers in an array called negList.
//So in main main i passed the array as parameter and the size;
void lucknumberlist(int favnum[], int size) {
int even = 0, odd = 0, neg = 0;
int evenArray[even];
int oddArray[odd];
int negArray[neg];
if(favnum[even] % 2 == 0) {
evenArray[even] = favnum[even];
[Code] .....
View 1 Replies
View Related
Sep 23, 2014
I am puzzled with the strange behavior of my code below. The code has an apparent error but the results are correct. I am trying to put two arrays (chara and shuffled) into a third array join. The first 10 elements of 'join' should have the elements of 'chara' and the second half should have the elements of 'shuffled'.
You will note that in the second For loop, I am using 'chara' instead of 'shuffled' but when I print the contents of 'join' I am getting the correct numbers.
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
On the other hand if I replace 'chara' with 'shuffled' in the second For loop, I am getting incorrect results.
1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,
Why is this happening? (I am using Codeblocks.)
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int chara[]={1,2,3,4,5,6,7,8,9,10};
int shuffled[]={11,12,13,14,15,16,17,18,19,20};
[Code] ....
The question is cross-posted at: [URL] ....
View 6 Replies
View Related
Mar 6, 2015
I working on a big program, and it involves character arrays. What I want my function to do is create a seperate array that consists of the same number of "*" as there are letters in the word from the text file. For example, if the word sarc was up, the function show make ****. This was my attempt at it. I managed to reach this far. I can only fit in one "*". This is part of jumble game program I'm trying to make, and its in C language.
insert Code: void partialWord(char current[]){
int n;
int i;
n = strlen(current);
for (i = 0; i < n; i++){
current[i] = strcpy(current,"*");
}
printf("%s
", current);
}
View 7 Replies
View Related