characters (integer value)

Started by
43 comments, last by Roble 21 years, 1 month ago
Try something and ill help you out. Post whatever you try too.

Remember you can converty the char into an int value with atoi() You''ll probly want to loop through each character and then print out(to the screen or file...whatever your doing)the integer and the ''-'' character to the right of it.

By the way...Do you have a book on C or C++? If you dont ide suggest you getting one or looking up some tutorials. Thats if you want to program more. The program you''re making is fairly simple so after reading a good book it shouldnt be hard to do something like that at all.
Advertisement
Well, this is what I do have:


  #include <string.h>#include <stdio.h>#include <stdlib.h>#include <iostream.h>int main (){  	unsigned count = 0;  	char szInput[256];  	char *ptr;	int i = 0;	printf("Enter the sentence please\n");  			cin>>szInput;	szInput[strlen(szInput) +1] = ''\0'';	// Get the the first letter	ptr=strtok(szInput, "-");	if(!ptr)		return(0);	cout<<(int)ptr;	// Get all the rest	while((ptr=strtok(NULL, "-")) != NULL)        cout<<(int)ptr;	printf("\n");	//////////  		return 0;}  
I M Teh n00B11!!!1
Ok, when did the forums start to exist for the sole purpose of teaching people who doesn''t feel like reading a book/doc how to code?

--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.
That code wont work at all. For one your breaking everything down by the ''-'' character. A typical sentence wont be How-Are-You. And even if thats how you want it your trying to get the int value for the whole word when you need to get the int value of each individual character and seperate them all with a ''-''. If you dont understand how to do that then look back in the early pages of this forum, I believe I already made an example for it.

quote:
Ok, when did the forums start to exist for the sole purpose of teaching people who doesn''t feel like reading a book/doc how to code?


This is true, so as I said you really should pickup a book and read it. No one is going to help you make your code as I have done, but when your confused about a subject or how to do something helpful hints and ideas will be given.
quote:Original post by Roble
How would I make a program that takes the integer value of a character, and turns it into the character?


I believe you can also use the int() function.

If you pass in a number it will return the ASCII character. If you pass in a character it will return the ASCII value.

Patrick

This topic is closed to new replies.

Advertisement