C++ :: How To Convert A Single Character Into ASCII
Jan 26, 2014
I am making a text encrypter and I have to convert text into ASCII codes. I know how to convert a single character into ASCII -
#include <iostream>
using namespace std;
int main() {
cout<<"Text to ASCII converter"<<endl<<"Enter text to convert into ASCII - ";
char text; //defining input type, which is single character
[Code] ....
Try it here - URL.....Is there any way to run a similar program, which converts a string with spaces into ASCII code?
Im programming a roguelike game using visual c++ Microsoft express 2010 and i made a multidimensional array for my first map. I have the walls as # and was wondering how i could turn those into ascii symbol 219. Also i need to know how to turn specific text certain colors.
i am doing an embedded project on avr microcontroller ATmega8515.actually my project is smart card based electricity billing using UART interfacing..so in this module HEX to ASCII conversion is not possible for me...
Using C . I have been tasked (for a University assignment) to create a program that will enable a user to upload an image and convert that image into ASCII text using SDL on a Linux system. I've managed to open a window, display an image (non-selected) and convert it into grayscale using
case SDLK_g: for (int y = 0; y < image->h; y++) { for (int x = 0; x < image->w; x++) { Uint32 pixel = pixels[y * image->w + x]; Uint8 r = pixel >> 16 & 0xFF; Uint8 g = pixel >> 8 & 0xFF; Uint8 b = pixel & 0xFF; Uint8 v = (0.212671*r)+(0.715160*g)+(0.072169*B)/>; pixel = (0xFF << 24) | (v << 16) | (v << 8) | v; pixels[y * image->w + x] = pixel;
I am absolutely clueless as to how I can get the user to upload an image to the program and then begin the image -> ASCII conversion. I've found seem to be written in C++ or C# to make the conversion I should be using the GetPixelColour command?
The code is supposed to convert characters from an array into their respective ascii integers, and append a 0 if the number is less than 3 digits long. It then supposed to put it all together into one string.
Code: #include <stdio.h> #include <string.h> #include <stdlib.h> int main(void){
char file[] = "This is a test"; char *ptr = file; int length = strlen(file); int i, numbers[length];
I wish to convert a character directly to a string for a top-secret project I'm working on. It needs to be portable across various machines with different sized Indians.
Code:
#include <stdio.h> int main(void) { const int i = 0x0041; const char *str_p = (char *) &i; }
[code]....
I want this to output an 'A', but I'm not sure this code will work on my friend's mom's S/360.
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;
Double values are stored in text file. 23.5 36.8 34.2 ... My teacher told me to read them character by character and then make words, like i have to read "2" "3" "." "5" and now have to make it or treat it as word and then using atoi(). I have to convert it into double. but i dont know how to do this....
I have to optimize a code for below scenario. I am reading stdin (a file redirected to stdin) character by character. How many chars are going to come is not known. After every few chars there is a seaparator. e.g $ as below
rhhrkkj$hghjhdf$ddfkrjt
While reading, if the separator arrives I'm processing the string stored before that separator and then continue reading stdin in same fashion, till EOF. I am using getc(stdin) to read chars.
Using gprof I can see most of the program time is spent inside main() , for this reading logic. Rest of the program is just some insert and search operations. I am getting time of 0.01 secs at the moment, want to reduce further.
In my program, I'm supposed to read a text file (the name of which is given to me as a command line paramater, as long with an integer), and display the text in a specific format (each line can only be as long as the integer). However, I'm having trouble even reading the text file. I don't know the syntax. I'm only allowed to edit the function that does the formatting, and the code in that is
void typeset (int maxWidth, istream& documentIn)
I don't know how to 'read' the file, as most examples online are ifstream, or openFile or something like that. What I want to do is just read the first character of the file, and continuously keep reading characters until the end of the file.
So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:
#include "NewString.h" using namespace ...; int main()
[Code].....
Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.
I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:
I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.
I have some ascii characters in a char variable.ex - char buf[100]="ab*(z&";
So each of the char in that char array will have some hex value.ex- *'s hex value is '2a'.
And I have a long long int variable in which there is a 64 bit hex value.
ex- long long int k=0x0000888888888888;
Now i want to subtract the char buff's hex value in k. How to accomplish it.
That is 0x0000888888888888 - 0x000061622a287a26 = 0x000027265e600e62 (final result in a buffer or a long variable is okay)
Later i want to reverse the result as 26e006e56272.It should be stored in a variable such that i should be able to access each byte from it(ex- '72'(last 2 hex digits))
I know how to find find ASCII value of given character, but I am not getting how to find ASCII value of given string. For example I want to find ASCII value of string "HELLO",so how to do that.
I have to Write a program to produce that makes four triangles and a pyramid. I have to ask the user they height of the triangle and prevent the user from entering a height any larger than 25. It should look like this.
Enter the height of your triangle/pyramid: 3
*** ** *
* ** ***
* ** ***
*** ** *
* *** *****
im having tourble with 3 and 4th and also pyramid.
HERES WHAT I HAVE SO FAR.
#include <iostream> #include <iomanip> #include <string> using namespace std; int main () { int input = 0; cout << "Please enter the height of your triangle/pyramid: ";