C :: How To Find Amount Of Space In Char Array

May 14, 2013

How do you find the amount of space in a char array?

View 11 Replies


ADVERTISEMENT

C :: Find The Length Of Char Array

Sep 25, 2014

I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.

View 2 Replies View Related

C :: Find The Least Amount Of Coins Required To Make A Value

Mar 8, 2014

Write a program in C that will allow a user to enter an amount of money, then display the least number of coins and the value of each coin required to make up that amount. The twist to this program is the introduction of a new coin - the jonnie (value = $1.26). Therefore, the coins available for your calculations are: Twonies, Loonies, Jonnies, Quarters, Dimes, Nickels and Pennies. You can assume the amount of money user enters will be less than $100.00.

User enters $4.53. Your output should be:

The least number of coins required to make up $4.53 is 4. The coins needed are:

1 Toonie $2.00
2 Jonnies $2.52
1 Penny $0.01
$4.53

I'm wondering if i'm close. I'm stuck on what to do for the output. This is what i have so far.

Code:
//Start
#include <stdio.h>
int main() {
//Get user input for amount of money

//Input
int i;
//Store input from user

[Code] .....

View 3 Replies View Related

C++ :: Remove Char Without Space From String

Aug 6, 2013

I need to remove a char from string that found ;

For example : string- abcdfe
the char ch is - c
and the return new string is : abdfe.

I did as follow:

void removeChar(char string2[SIZE], char ch) {
char input= 'a'; // for example replace something
int i=0;

if(string2[i]== ch && string2[i]!='/0') {
string2[i]= input;
}
i++;
}

and in the main : I only called to this function above and print string.

View 4 Replies View Related

C++ :: Find K Nearest Neighbors Of All Points On 2D Space?

Oct 8, 2014

In this project you are asked to find K nearest neighbors of all points on a 2D space. The distance metric that you are going to use is simply the Euclidean distance example;

inputs:
10 2
3.57 3.18
84.91 27.69
93.40 4.62
67.87 9.71
75.77 82.35
74.31 69.48
39.22 31.71
65.55 95.02
17.12 3.44
70.60 43.87

Outputs:

1 9 7
2 10 3
3 2 4
4 2 3
5 6 8
6 5 10
7 10 9
8 5 6
9 1 7
10 2 6

View 12 Replies View Related

C++ :: How To Read Input Of Arbitrary Amount Of Numbers Instead Of Specific Amount

Feb 25, 2015

I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.

javascript:tx('
#include <iostream>
using namespace std;
//******************************************
//CLASS COMPARATOR
//******************************************

class comparator {
public:
comparator();

[Code] .....

And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.

View 3 Replies View Related

C++ :: Reserve Space For Array?

Oct 12, 2013

In my code I have a template class.

In the contructor, I create a new array arrray.

A pointer to this array is saved as an attribute.

The purpose of this attribute is that I should be able to call the array from within another function be typing *p or *(p+1) etc.

The only thing I forgot is that the array doesn't exist anymore when the constructor is done, right?

This means the space is no longer reserved for this array and the space is used for other things.

Is there a way to keep the array space reserved (even when the array does not exist anymore at the end of the function)?

View 1 Replies View Related

C++ ::  add A Space Into Character Array

Apr 29, 2014

I have a character Array 'Hello'

I want to add a space in whatever space the users chooses.

"Where do you want to add space? --> " 3 String after space is added --> 'Hel lo

View 4 Replies View Related

C++ :: How To Capitalize Letter After A Space In Array

Jul 25, 2013

The assignment is to read a data file with a list of names, capitalize the first character of the first and last name by making an array and subtracting 32 from the character, and then outputting the names onto the screen. So far I have:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("Names.txt");

[Code] ....

this allows me to read a name, and capitalize the first letter of the first name. How to capitalize the first letter of the last name.

View 2 Replies View Related

C++ :: Total Amount Of Even Numbers In Array - Expected Primary Expression Before Int

May 30, 2014

Trying to write a function, Even, that will tell you the total amount of even numbers in the array

#include <iostream>
using namespace std;
const int MAX_ROWS = 3;
const int MAX_COLUMNS = 2;

int Even(int A[int length][int width], int length, int width) {

[Code] ....

View 1 Replies View Related

C++ :: Structures - How To Update Space Ship Position In Array

Apr 7, 2013

I want to do this but do not know exactly how to do it:

Create an array of space ship objects and write a program that continually updates their positions until they all go off the screen. Assume that the size of the screen is 1024 pixels by 768 pixels.

I have begun to write a bit code but the problem is when you want to see the space ship moving step for step on the screen I do not know how to create the ship visible so you can see it is moving. Here's my code so far

Code:
#include <iostream>
using namespace std;
struct SpaceShips
{
int x_coordinate;
int y_coordinate;

[Code ......

View 4 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

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

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

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 :: Char Array With A Phrase To Char Word

Nov 28, 2013

I need to do a function that copy every word from a text to a char word. How can i do it?

View 5 Replies View Related

C :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

#include <stdio.h>
#include <stdlib.h>

[Code] ....

View 4 Replies View Related

C++ :: Convert Uint8 Array To Unsigned Char Array?

Mar 2, 2012

I have the following code which attempts to assign a u_int8 array of 256 to an unsigned char[256]:

Code:
unsigned char testData[256]=pSample->data;

I get the compilation error:

error C2440: 'initializing' : cannot convert from 'const uint8_t [256]' to 'unsigned char [256]'

What is the safe way to cast or convert here?

View 3 Replies View Related

C :: How To Convert Char Array Into Int Array

Jan 24, 2013

I am writing code to multiply two int arrays and in my one function i am trying to convert the char array into an int array. I have tested many parts however i can not find the problem.

Code:

struct integer* convert_integer(char* stringInt){
struct integer *converted = malloc(sizeof(struct integer));
int length, i, *ints;
ints = (int *)malloc(10001 * sizeof(int));
length = strlen(stringInt);
printf("stringInt: %s with length of %d
", stringInt, length);
converted->size = length;

[Code]...

View 5 Replies View Related

C++ ::  How To Get Amount Of RAM Available On PC

Mar 6, 2013

I bet there's a simple function that can return the amount of RAM available on the computer, or perhaps the total RAM on the chip.

Basically I want a way of making sure my program never tries to allocate memory when it can't... I know that Windows should stop this happening anyway but I want to make sure the program can take care of certain things if it happens.

View 3 Replies View Related

C++ :: Get Word From Char Array

Jan 28, 2015

Let's say i have some text in char array Code: char text[] = "Hello my friend"; How can i get a seperate words from it? It should be like

Code:
char a[] = "Hello";
char b[] = "my";
char c[] = "friend";

Is it possible to do?

View 2 Replies View Related

C :: Int Array To Char (Binary Value)

Jul 19, 2013

I have an int array with the binary value of a char. How to to turn it into a char? I can transform it to an int but then I'm stuck.

Code:
#include <stdio.h>
int main() {
int a[260] = {0,1,1,0,0,0,0,1};
char buf[260];
int b=0;
for(int i=0; i<8; i++) {
b=10*b+a[i];
}
itoa(b, buf, 10);

View 6 Replies View Related

C :: Unable To Set Char Array

May 5, 2013

Code:

#include <stdio.h>
char * strcpy(char *restrict s1, const char *restrict s2);
struct item {
char title[20];
struct item *next;
} firstCard;
int main (){
strcpy(firstCard.next->title, "whatever");
}

I am unable to set firstCard.next->title

View 2 Replies View Related

C++ :: Char Array To String

Oct 19, 2013

I have some code:

char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);

After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".

Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.

Or is there something I'm missing? Maybe the termination character, or something.

View 1 Replies View Related

C++ :: Using A Pointer To Char Array

Aug 31, 2013

I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.

#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;

[Code] ....

View 3 Replies View Related

C++ :: Array Of Char - Shows More Than It Should

Nov 9, 2013

I have this code:

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");

[Code] .....

This program make a copy of the source array, then it removes each character and shows the obtained array.

And when i insert "abcdefghijkl"

it should show this: "

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("input.txt");
ofstream g("output.txt");

[Code] .....

View 1 Replies View Related

C/C++ :: Comparing 2D Char Array?

Jun 22, 2014

I am working on a program to find uppercase, lowercase and digits in a 2D char array. When I try to use an if statement to increase the counter, I get an error "no conversion from 'int' to 'char*'". This is the if statement I am using.

if(myArray[j] <='9' || myArray[j] >='0')

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







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