C/C++ :: Converting 8-byte Integer To String Based Integer

Oct 15, 2014

Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.

Ex: printf("0x%s
",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}

I wrote:

#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';

[Code] ....

0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?

View 4 Replies


ADVERTISEMENT

C++ :: Converting Integer To String Based On Digits

Apr 23, 2013

I want to convert the integer into a string.

int x = 693;
char chararr[max];

In my homework, x is unknown. but don't worry, I wont ask for the full code. I just need the part where you change the int into a string/array of char.

I'm thinking in circles from where to start?

View 2 Replies View Related

C++ :: Converting String Into Integer?

Nov 22, 2013

I'm trying to convert a string into a integer and when I call stoi(line) it causes the program to crash.

int main() {
vector<int> numbers;
int i;
string line;
ifstream myfile ("example.dat");

[Code] ....

The file being read from looks like:

3
12
23
34
12 34
12 12
34 23
23 23

View 1 Replies View Related

C/C++ :: Converting String Into Integer

Sep 26, 2013

struct time
{ int t;
    int h,m,s;    
};  
int main() {
    time t;
    int totalsecond;
    char A[10],B[10];

[Code] ....

It gives error at line no 12.

View 5 Replies View Related

C++ :: Converting String To Integer Array

Apr 17, 2014

For Example, it the entered string is: 0324152397 I want it to get stored in an array like-[0] [3] ...[7]. Secondly the string entered may be of any length that is defined only at run time. So, I also need to calculate string length. How could I do that.

View 2 Replies View Related

C++ :: Rounding And Converting To Integer?

Oct 4, 2014

Ok so I'm in a programming 1 class working with c++. I have the following assignment:

Write a C++ program that:
asks for and accepts the Percentage earned with as a double (i.e. 75.45)
rounds it to an integer (>= .5 rounds up, <.5 rounds down.)
prints the original Percentage and the corresponding Grade and Points exactly as shown below.
prints an error message for any input that is less than 0 or greater than 100.

For example, if user enters 89.4, the program prints out:
Percentage: 89.4% Grade: B Points: 3.00
You must use an if-else statement to do this in your program.
Use fixed and precision output manipulators (see Ch. 3) to display the values with the exact precision shown above.

IMPORTANT:
Each if statement condition should contain only one comparison! read this again
This means code that is similar to this is NOT okay:  if (Percentage >= 80.00 && Percentage <90.00)
This code is not acceptable because the if statement condition above has two comparisons.
(Hint: If you order your if-else chain statements correctly, you will only need one comparison in each.)

I have the program working, but I'm pretty sure I'm not rounding how my professor would like it to. This is my code:

#include <iostream>
#include <cmath>
#include <iomanip>

[Code].....

So my issue here is the rounding, and then theres the converting the double percetnage to an integer. In my next assignment I have to write the program with a switch statement.

View 3 Replies View Related

C++ :: Converting Integer To Vector And Back

Feb 15, 2012

I'm able to convert an integer to a vector<unsigned char> and back. However, when I try to use a nearly identical function designed for the long long data type, the last byte or two is broken.

Program code:

long long num = 9223372036854775551LL;
cout << "Before: " << num << endl;
vector<unsigned char> data = getBytes(num);
num = getLongLong(data);
cout << "After: " << num << endl;

Code for converting between vector<unsigned char> and long long:

Code:
vector<unsigned char> getBytes(long long value) {
int bytes = sizeof(value);
vector<unsigned char> data(bytes);
for (int i = 0; i < bytes; i++)
data.at(i) = (unsigned char)( value >> ((bytes-i)*8) );

[Code] ....

Output:

Code:
Before: 9223372036854775807
After: 9223372036854775552

Is there something special about long long that would prevent this from working? This problem doesn't happen with int.

View 3 Replies View Related

C++ :: Making Diamond Out Of Asterisks Based On Given Odd Integer Input

Sep 6, 2014

I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.

Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>

using namespace std;
int _tmain(int argc, _TCHAR* argv[]){

[Code] ....

View 2 Replies View Related

C++ :: Sorting Vectors Based On Value Of First Integer In Ascending Order

Feb 13, 2013

I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <windows.h>
using namespace std;
class orders {
public:
int IOT; // Incoming Order Time

[Code] ....

View 7 Replies View Related

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

C/C++ :: Converting Integer Number To Its 2's Complement Presentation

Jan 28, 2014

I am working on an assignment about converting an integer number to its 2's complement presentation. The binary representation is consisting of a single linked list.

As we all know, the steps of this converting is to taking the reminder of the absolute value, then flipping the 1 to be 0, and the 0 to be 1 in the binary number. And the last step will be to add 1 to the binary number invers.

I wrote a code that implements every thin correctly. However, when I reached the part of adding 1, the program was hanged.

int Absolute; //the first step is to convert the number to the binry reprezentation
Absolute = abs (value);// by take the Absolute value of the negative number, then find the
while (Absolute !=0) //the binary reprezentation {
int res;
res= (Absolute % 2);
pushFront (res);
Absolute /=2 ;

[Code] .....

View 11 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related

C++ :: Changing Integer Into New Integer With Simple Mathematical Operations?

Jun 15, 2014

changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).

View 4 Replies View Related

C++ :: Input Integer To A String?

Oct 20, 2014

i wanna put an integer into a string for example:

Code:
string name;
int num=8;
name= "George"
//

I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();

View 7 Replies View Related

C++ :: Read Integer To A String?

Oct 15, 2013

How do I read integers to a string and store then into a vector array?

I need to add two input digits i.e. "1234567878887777" and "123344543543543"

View 8 Replies View Related

C/C++ :: Convert String To Integer (hh/mm/ss)

Jul 9, 2014

I need to convert below value char *time="00.00.05".

I need to convert this to hh/mm/ss ....

View 2 Replies View Related

C++ :: String Integer Value - Input / Output

Aug 14, 2013

Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.

Sample Run 1:
Input -> A111B222C
output -> 9

Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62

View 1 Replies View Related

C :: Assign Pointer Of A String To Integer

Mar 22, 2014

I have this code:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[code]....

What I want is basically to assign to the *p the pointer of the string so that i could do the following printf(" print string %s",*p); so i dont know how to do that.

View 6 Replies View Related

C :: How To Convert Part Of String And Integer

Jan 2, 2014

I'm having a problem converting part of a string to an integer.I used strtok to seperate my string and I have also a function for atoi but how to apply it to my strtok function.What i need is to change the char *years to an int.Have a look of what I got:

Code:
int main() {
char sentence[]="trade_#_2009_#_invest_#_DEALING";
char *word=strtok(sentence, "_#_");
char *year=strtok(NULL, "_#_");; // assigning NULL for previousely where it left off
char *definition=strtok(NULL,"_#_");
char *synonyms=strtok(NULL,"_#_");

[code]...

View 2 Replies View Related

C :: Reading String And Checking If Integer

Nov 23, 2013

wrote this program to check if a string is an integer. It checks for + or - sign at the front of it, but it spat out some errors.I think I broke it.Here is the code:

Code:

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int getInteger(char*);
int main(void) {
char str[99];
int x;
}

[code].....

View 2 Replies View Related

C++ :: Convert From Integer To Character String

Oct 2, 2013

I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?

void convertToString(unsigned long con) {
unsigned long product[10];
char cString[10];
const unsigned long begConvert = 10 ^ 10;

[Code] ....

View 4 Replies View Related

C++ :: How To Turn String Integer Into Array

Jul 23, 2013

int main () {
string integer1;
string integer2;
cout <<" enter your first number: " << endl;
cin >> integer1;
cout << endl;
cout << integer1 << " is your first number" << endl;
}

Now how do I turn the string integer into an array?

View 5 Replies View Related

C++ :: Adding String But It Return Some Integer Value

Jun 10, 2013

string str = "sfsdfsd"

and i want to add like str[3]+str[4]

but it return some integer value

View 3 Replies View Related

C :: Assign Length Of String To Integer Variable

Dec 25, 2014

What I'm trying to do is to assign the length of a string to an integer variable. This is what i tried, it did not work.

Code:
printf("Enter a string
");
fgets(test_pass, 30, stdin);
strcpy(x,(strlen(test_pass)));
printf("%d", x);

This was just a test, and it did not compile. How to do this?

View 4 Replies View Related

C :: Convert String Made Of Many Numbers To Integer

Jan 6, 2015

I am supposed to convert a string made of many numbers between every number spaces are between, to an integer variable for every number..

How am I supposed to get over this problem?

Example: String: " 322 52 231"

View 1 Replies View Related

C :: Convert Elements Of String Array To Integer

Feb 4, 2014

I'm just learning and C. Here is a code snippit from a program that will compile. It's function is to validate credit card numbers. I have an error I can't find though. the last print statement shows the conversion in reverse string (as integers). Here is the code:

int main (void)
{
char cn[17];
char *cardtype;
int n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14, n15;
int s1,s2,s3,s4,s5,s6,s7,s8;
int oddsum;
int sum;
int total;
int validate;
}

[code]....

View 14 Replies View Related







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