Thread: ascii

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    Unhappy ascii

    ok i have this program that im trying to make that outputs the ascii character and its value iv got the following program but instead of going "a = 65 b = 66" it goes "abc = 65 = 66 = 67"

    #include <stdio.h>
    #include <iostream.h>

    int i=0;
    int j=0;
    int ascii_value=1;
    //////////////////////////////////////
    // //
    // main function //
    // //
    //////////////////////////////////////

    int main()
    {
    while(i<255) //set the number of characters to display
    {
    while(j<3) //how many characters to display per line
    {
    if(i>=255) //if i is greater than 255 exit
    {
    return 0; //exit
    }
    cout<<" = "<<ascii_value; //print the "." form of the ascii text
    putchar(i); //print the char
    i++; // increase the ascii char we are on
    ascii_value++; //increase its '.' format
    j++; //increase the 3 to a line loop
    }
    j=0; //reset the 3 to a line loop
    i++; //increase the ascii char again
    cout<<endl; /start printing on new line
    }
    return 0; //exit program
    }
    Last edited by c++.prog.newbie; 11-24-2001 at 09:26 PM.

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    why not use only one loop and do

    char c;
    c=(char)i;
    cout << c << "=" << i << endl;

    or use printf, it's easier

    printf("%c=%d",i,i);

    Oskilian

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Code:
    int y = 0;
    for(int x = 33; x <255 ; x++){ // 1 - 32 are control chars
    cout <<(char)x << ";" << x << "\t";
    y++;
    if(!(y % 10)) cout << endl; //after 10 printed go down a line
    
    }
    Like this...

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    thanx but what does

    if(!(y % 10))

    mean

    and what part of the program is writing the ascii char (eg.
    putchar(9))

  5. #5
    I think it means:

    if(!(y == 10))

    That seems like the logical thing to be
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  6. #6
    Unregistered
    Guest

    ...

    that if(!(y % 10)) cout << endl; statement means if 10 divides into y without a remainder, then print a newline.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII character with ASCII value 0 and 32
    By hitesh_best in forum C Programming
    Replies: 4
    Last Post: 07-24-2007, 09:45 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Office access in C/C++ NOT VC++!! :)
    By skawky in forum C++ Programming
    Replies: 1
    Last Post: 05-26-2005, 01:43 PM
  4. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM