The Daily Click ::. Forums ::. Non-Klik Coding Help ::. ASCII 'getintchar' program
 

Post Reply  Post Oekaki 
 

Posted By Message

Galaxy613



Registered
  29/01/2003
Points
  1765
20th April, 2004 at 21:18:58 -

Loonng Story short, I came up with the idea of making a int that gets a char from 'getchar();' and shows the char AND the int value! I betcha I'm not the first one to make this program but's it's really really neat to me!

#include <stdio.h>
#define nl printf("\n")//time saving marco

int main(){ //'getintchar' program
int mychr;

printf("ASCII Number Printer 1.0\t\tby CKarl\n\
Type anything and press enter to see the ASCII number next to the char!\n\
Press tab then enter to exit\n");

do{
mychr = getchar();
nl;
printf("%i\t%c",mychr,mychr);
}while(mychr != 9);

return 1;
}






test outputs:
Image

>BTW<
Linefeed(enter) is 10 and you can't see the character and it always slaps it on sence you pressed enter, for excixse someone could make it so it doesn't print a line feed

Image Edited by the Author.

 
Image
My forum: http://subsoap.com/ck/forums/index.php

Galaxy613



Registered
  29/01/2003
Points
  1765
21st April, 2004 at 11:22:59 -

...any comments?

 
Image
My forum: http://subsoap.com/ck/forums/index.php

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
21st April, 2004 at 11:52:29 -

handy, definitely, but it could do with being in windows form (with two little edit boxes side-by-side)

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Galaxy613



Registered
  29/01/2003
Points
  1765
21st April, 2004 at 12:04:58 -

one problem with that...I know NOTHING about ANY TYPE of GUI with either C OR C++ UNLESS you know of a good tut...you won't be seeing any window apps for this

 
Image
My forum: http://subsoap.com/ck/forums/index.php

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
21st April, 2004 at 12:10:56 -

this one's good:

http://www.winprog.org/tutorial/


 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
21st April, 2004 at 12:46:03 -

Modified program to remove the linebreak.

#include <stdio.h>


int main(){ //'getintchar' program
int mychr;

printf("ASCII Number Printer 1.0\t\tby CKarl\n\
Type anything and press enter to see the ASCII number next to the char!\n\
Press tab then enter to exit\n");

do{
mychr = getchar();
if (mychr != 10) printf("\n%i\t%c",mychr,mychr);
}while(mychr != 9);

return 1;
}


 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
21st April, 2004 at 12:53:39 -

you could shrink that even more:

while((mychr = getchar()) != 9) {
if (mychr != 10) printf("\n%i\t%c",mychr,mychr);
}


 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
21st April, 2004 at 13:48:45 -

Kris, handy webpage that, thanx

 
n/a

Galaxy613



Registered
  29/01/2003
Points
  1765
21st April, 2004 at 16:18:50 -

V1.05!

major update: in V1.00 I forgot to add a xtra '\n' in 'printf("\n%i\t%c",mychr,mychr);' at the end for another promt.


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <windows.h>

// the now useless functions that I keep here to just becuz',
// cls() needs working..
void cls(void); //handy cls function
void locate(int x,int y); //nice locate func

#define nl printf("\n")
#define intro printf("ASCII Number Printer 1.05\t\tby CKarl with help from Kris and Chris\n\
Type anything and press enter to see the ASCII number next to the char!\n\
Press tab then enter to exit\n")

int main(){ //'getintchar' program
int mychr,flg=0;

intro;

while((mychr = getchar()) != 9) {
if (mychr != 10) printf("\n%i\t%c\n",mychr,mychr);
}


return 1;
}

void cls(void){
/*union REGS regs;

regs.h.ah=0x06;
regs.h.al=0x00;
regs.h.bh=0x07;
regs.h.ch=0x00;
regs.h.cl=0x00;
regs.h.dh=ROWS-1;
regs.h.dl=COLS-1;
int86(VIDEO,Žs,Žs);*/
int a;
for(a=0;a<30;a++){
nl;
}

locate(0,0);
}

void locate(int col,int row){
/*union REGS regs;

regs.h.ah=0x02;
regs.h.bh=0x00;
regs.h.dh=row;
regs.h.dl=col;
int86(VIDEO,Žs,Žs)*/
HANDLE OutputH;
COORD position = {col, row};
SetConsoleCursorPosition(OutputH, position);
}


reading the API tutorial... I don't know how it'll show the output so if anyone has input(har har har) on how I should do it'll be gr8t

Image Edited by the Author.

 
Image
My forum: http://subsoap.com/ck/forums/index.php

Kramy



Registered
  08/06/2002
Points
  1888
21st April, 2004 at 17:22:32 -

Commented Jamascript conversion:


// Oh so many comments!

// Make Window
myWindow = New Window(320,240,0xFFFFFF,15,"Get Char Value");
// Center window so it's easier to see
myWindow.CENTER();
// For Inputting Value
myEdit = New Edit(myWindow,"Enter String Here",4,4,312,104,Edit.VSCROLL,Edit.MULTILINE);
// For Result
myEditResult = New Edit(myWindow,"Click Button for Result",4,112,312,104,Edit.VSCROLL,Edit.MULTILINE);
// Button for calling function
myButton = New Button(myWindow,"Get Values",252,216,64,20);
// Mouse Clicked
myButton.OnClick = Click;


Function Click(btn)
{
// "myButton" clicked, so get Result
If(btn == myButton)
{
// Calls function and passes string
myEditResult.SetText(GetChars(myEdit.GetText()));
}
}

// Get Char Values of String
Function GetChars(pString)
{
// String to Get Values from
This.myString = pString;
// Result to store Values
This.myResult = "";
// Get all Char Values
For(n = 0;n < This.myString.Length();n++)
{
// Get Char Value
This.myChar = This.myString.SubString(n,1);
// Store Char Value
This.myResult += This.myChar.GetAscii()+".";
}
// Return result to editbox
Return This.myResult.SubString(0,This.myResult.Length()-1);
}

// Keep Program Running
While(1);

Edit: Does anyone else find the CODE tag makes it hard to read? All those line breaks, I mean.


Image Edited by the Author.

 
Kramy

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
21st April, 2004 at 17:32:35 -

Karl, did you know about inline functions? They work more-or-less the same as pre-processor #defines but are a lot neater:

inline void intro() {
printf("ASCII Number Printer 1.05\t\tby CKarl with help from Kris and Chris\n\
Type anything and press enter to see the ASCII number next to the char!\n\
Press tab then enter to exit\n")
}


Now whenever you do intro();, the code from the intro() function will just be inserted in its place, instead of the function actually being called, so there's no speed loss.

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Mr Icekirby



Registered
  18/12/2003
Points
  846
21st April, 2004 at 17:49:05 -

im confused, very confused

 
Mr Icekirby says so!
OBEY ME!

Galaxy613



Registered
  29/01/2003
Points
  1765
21st April, 2004 at 18:43:10 -

neato Kris! thx!!

 
Image
My forum: http://subsoap.com/ck/forums/index.php

Cazra

Crazy?

Registered
  24/07/2002
Points
  4472

Game of the Week WinnerVIP Member
22nd April, 2004 at 07:04:46 -

C++ version:

#include <iostream>

#include <stdlib.h>

int main()
{
char str[9999];
int index;
cout<<"*********************\n";
cout<<"* C++ ASCII printer *\n";
cout<<"*********************\n";
cout<<"\nby: Snerlin of Neonair\n\n";
system("PAUSE");
do
{
cout<<"Type something.\n";
index=0;
cin >> str;
do
{
cout <<"\n"<< (int)str[index] << "\t\t" << str[index];
index++;
}while((int)str[index]!= 0);
cout << "\n\n";

}
while(str[0]!='\n');

return 0;
}


If you type a phrase, it'll print every word in ther phrase, but it won't print spaces.

Image Edited by the Author.

 
n/a

Galaxy613



Registered
  29/01/2003
Points
  1765
23rd April, 2004 at 14:14:09 -

neat SoN!

 
Image
My forum: http://subsoap.com/ck/forums/index.php
   

Post Reply



 



Advertisement

Worth A Click