C :: How To Print The Max Number Row In Relation To The Char Arrays Row

Mar 30, 2013

I have most of the code working properly, but I'm having trouble with a certain area. Currently I have multiple 2D arrays. One is a char array and the other is an int array. In the int array I have to find the max number in each column, which I've done. The problem is, I need to print the max number's row in relation to the char array's row.

For example,

Code: int array[2][3] = {60 50 30 0 100 1}

The max numbers are 60, 100, 30.

char array[2][length+1] = {nameOne nameTwo}

How it needs to print:

nameOne has max score of 60.
nameTwo has max score of 100.
nameOne has max score of 30.

I just can't understand how to compare the two arrays in the right way, so it'll know that nameOne is associated with the numbers in row 0 and nameTwo in row 1, etc.

View 1 Replies


ADVERTISEMENT

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C/C++ :: Using Print Statement To Print Certain Number Of Spaces

Sep 1, 2014

is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?

for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}

This is suppose to output

t=-3 *
t=-2 *
t=-1
.
.
.

View 2 Replies View Related

C++ :: Relation Between A Container And Allocator

Mar 30, 2014

To my understanding, a Container should have an Allocator member data, which is used internally.

Question: what happens, for example, when we swap() two containers that use different allocators?

Must the allocators be swapped as well?

Must all elements of the container be reallocated when the allocator is changed?

View 7 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.

how i can keep the local position and distance ?

View 14 Replies View Related

C/C++ :: Pointers In Relation To Data Types?

Mar 7, 2014

how to correctly use pointers within relation to function parameters and main source file.

I noticed that char types, for example char myVariable[50]; which is an array, does not seem to require a pointer as if it already has one built in? as opposed to char *myVariable; which seems to need one - i assume this is because char has different ways to store memory in relation to pointers, because of there being multiple ways to store a string, and memory allocation as a part of that. - i stared C a few weeks ago and feel that it is difficult to progress without nailing down pointers. Also address operators provide confusion for me and written tutorials are not so clear because there are different ways to use these operators.

View 4 Replies View Related

C++ :: Relation Between Allocator And NodeAllocator In A Container?

Mar 31, 2014

Consider a singly-linked list container.

Being constructed with an alloc<T>, it will rebind it as alloc<node<T>> for internal use.

Question: is allocator_type the same as alloc<T> or as alloc<node<T>>?

View 2 Replies View Related

C++ :: How To Print Unsigned Char

Apr 23, 2013

How do I print an unsigned char in c++? E.g.

unsigned char a[100] = "acdef";
wprintf(L"a is %u
", a);
wcout << "a is " << a << endl;

gives

a is 2880488
a is 002BF3E8

and not

a is acdef
a is acdef

??

what is the difference between unsigned char and char?

View 6 Replies View Related

C/C++ :: Read And Print A Char Array

Nov 25, 2014

In this project I need to develop few functions to work with graphics card. I work in minix and this is pretty rubbish.

I'm having an hard time to read a pixel map, or atleast ro print it on my main function.

I have a read_xpm function, which is given, therefore, working.

char *read_xpm(char *map[], int *wd, int *ht)

then I have a pixmap.h file which gives some examples of pixmap images that I can use as example:

static char *pic1[] = {
"32 13 4",
". 0",
"x 2",
"o 14",

[Code]....

I tried something like read_xpm(xi, yi, *xpm[0]); but I'm guessing I need to index that array and run all those chars in order to show them.

View 3 Replies View Related

C :: How To Reserved Int Number And Print As Float Number

Nov 24, 2013

How to reserved int number and print as float number ?

View 1 Replies View Related

C :: Print Two Arrays On Same Table After Sorting

Jul 11, 2013

Having trouble with homework involving (title). Here is the assignment:Write a program that allows the user to enter 10 numbers from the keyboard. Sort the numbers using any sort routine you wish. The output from your program should be 2 columns of numbers. The left column should be the numbers in the order they were originally entered and the right column should be the sorted list. The columns should be labeled. You will need 2 arrays to accomplish this.

Use separate functions for input, sorting, and printing.So, I have to use separate functions for each of these. I would think it would be easiest to do the input in Main() and then the sorting and printing in another function, but of course since you can't return arrays I am kind of stuck on how I return the new array after sorting. I thought about doing the sorting in Main(), but then I would need to still do the original arrays input in a function and would still run into the same problem.

Here is what I have so far:

Code:

//Cameron Taylor
#include <stdio.h>
#define MAXARRAY 10
int highLow(int[], int);
int print(int[], int[], int);
int main (){
int unsorted[MAXARRAY], i, j, temp;

[Code]...

I know it seems simplistic right now, but I am just trying to get it to work first and then go back and beautify it up a bit.

View 9 Replies View Related

C++ :: Print Linked List But As A Vector Of Char

Aug 26, 2013

I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:

char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list

[Code] ....

But when I print that, I get a bunch of weird symbols...

View 7 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C :: How To Save Char Arrays To Disk

Dec 29, 2013

lets say I have a char array with four elements but only one char is used, does it write four elements or just one?

View 3 Replies View Related

C++ :: Comparing Two Char Arrays Alphabetically

Sep 14, 2013

I want to compare alphabetically two arrays. I try this:

char a[10] = "AABC";
char b[10] = "ZABC";
if(a > b) cout << a;
else cout << b;

But it always outputs a. How can I compare char arrays?

View 3 Replies View Related

C++ :: Template Specialization For Char Arrays

Jun 8, 2012

I'm trying to get template specializations working for char * as well as for char[]. I.e. in the following code the last test does not use the specialization and fails:

Code:
#include <string>
#include <iostream>
#include <cstring>
template<typename T1, typename T2>
bool compare(const T1& lhs, const T2& rhs) {

[Code] ....

View 4 Replies View Related

C++ :: Program Compiles But Refuses To Print Out Char Grades?

Nov 10, 2014

#include <fstream>
#include <ostream>
#include <iostream>
#include <iomanip>

using namespace std;

const int NAMESIZE = 15;
const int MAXRECORDS = 50;

[Code] ....

View 2 Replies View Related

C :: How To Correctly Use Realloc On Array Of Char Arrays

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

C++ :: Char Arrays - Getting User Input Through Different Methods

May 29, 2014

I've been experimenting with char arrays and getting user input through different methods.

int main() {
char userInput[21];
/*I understand that over here, a maximum of 20 letters can be input, and only letters before a space will be stored in userInput*/
std::cin >> userInput;
std::cout << userInput << std::endl;

[Code] ....

As I was testing, whenever I would input a single word for userInput (for example "hi"), the program would work as expected: it would output "hi" and I'd be able to input a sentence of sorts for userInput2 (for example "hello world") and have it outputted.

But if I were to input more than one word for user Input (for example "hi how are you"), the program would output "hi" as expected, but it wouldn't let me input anything for userInput2 and would just output the rest of the first input; in this case, "how are you" would be outputted and the program would end. I am not aware of the logic error at play.

View 7 Replies View Related

C++ :: Send Two Or More Char Arrays Over TCP Socket (winsock)

Nov 21, 2013

send(sConnect, (userinput, key), 256, 0);

sConnect is already predefined as a socket

Key is a character array of [32]

Userinput is a character array of [256]

How can you send both of them at the same time using the send function without having to create a separate connection?

View 1 Replies View Related

C++ :: Passing Char Arrays Between Functions Of Same Class

Nov 16, 2013

I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.

Here's my code:

Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph

[Code] ....

View 4 Replies View Related

C/C++ :: Compare Two Arrays And Print Out A List Of All Songs Without Repeating

Mar 11, 2014

I have two arrays:

const char *mymp3list[15] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15" };
const char *myFriendsmp3list[20] = { "Song 1", "Song 2", "Song 3", "Song 4", "Song 5", "Song 6", "Song 7", "Song 8", "Song 9", "Song 10", "Song 11", "Song 12", "Song 13", "Song 14", "Song 15", "Song 16", "Song 17", "Song 18", "Song 19", "Song 20"};

And I want to compare the two arrays and print out a list of all the "songs" without repeating any.

I've figured out how to print the just the duplicates using:

for (int count = 0; count < SIZE1; count++){
for (int i = 0; i < SIZE2; i++){
if (mysonglist[count] == friendsonglist[i])
cout << mysonglist[count] << "";
}
}

But I'm stumped on how to print a full list containing no duplicates.

View 4 Replies View Related

C :: Eliminating Use Of Malloc / Free When Copying Char Arrays

Apr 6, 2014

This program works as expected:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
}

[code]....

But I don't like how I had to use malloc and free. Is there a different way to accomplish copying the string into a char pointer without resorting to dynamic memory allocation?

View 1 Replies View Related

C++ :: How To Print Out Second MIN And MAX Number Without Using Array

Oct 13, 2014

How can i print out the SECOND MIN number and MAX number without using array?

cout << "Please input a positive integer: ";
cin >> input;
min = input, max = input, secondmin = input;
do {
cout << "Please input a positive integer: ";
cin >> input;

[Code] .....

View 7 Replies View Related

C/C++ :: Have To Identify Odd Number And Print Them

Apr 10, 2013

#include<stdio.h>
#define TRUE 1  
int formOddInt(int n);  

[Code]....

View 5 Replies View Related







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