1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pointers

Discussion in 'General Discussion' started by Leard, Jan 9, 2016.

  1. Leard

    Leard Crash Landed

    • Member
    I inserted pointers to store the inputed value from c or a or d to a pointer then from pointer to put in variable called "input" when i press b.
    Now i want when i press c then when i press b to run the loop how many times i press c and b.

    #include <iostream>
    using namespace std;

    int main( )
    {
    char character, *input;
    int i, it;
    cin >> character;

    if ( character == 'c' || 'a' || 'd') {
    for( i = 1 ; i <= 9 && character!='b' ; i++ )
    cin >> character
    input=&character;}

    if (character == 'b'){
    for( it = 9; it > 1 ; it-- )
    cout << "Variable is " << *input << ' ' << it << endl;
    }
    return 0;}


    my output with this program is for example:

    c
    c
    c
    c
    Variable is b 9
    Variable is b 8
    Variable is b 7
    Variable is b 6
    Variable is b 5
    Variable is b 4
    Variable is b 3
    Variable is b 2
    b
    process returned 0 <0x0>...


    i want to output this ->

    d*
    c**
    a***
    c****
    d*****
    b
    Variable is d***** 9
    b
    Variable is c**** 8
    b
    Variable is a*** 7
    b
    Variable is c** 6
    b
    Variable is d* 5
    c^
    b
    Variable is c^ 4 ..
    Leard, Jan 9, 2016
    Last edited by Leard; at Jan 9, 2016
    #1
  2. NeonSturm

    NeonSturm Back Into Space

    • Member
    I request a thread movement from "General Discussions" to "Nerd Out Zone".​

    You need 5 places in your hardware to store d* c** a*** c**** d***** values

    BTW: Using BB-tag for PHP-code, because there is no C-code-tag.
    And to remind that it is looks awful in the "Dark Theme" for the forum.​
    PHP:
    int main( )
    {
    char character, *input// I am not sure what difference declaring it as *input should make here. It is not an array
    int iit;
    cin >> character;

    if ( 
    character == 'c' || 'a' || 'd') {
      for( 
    <=&& character != 'b' i++ ) // for seems to be missing brackets {}.
      
    cin >> character// always puts the character into the same place in your hardware ((missed a semi-colon in the OP))
      
    input=&character// always accesses this same place. This is the only place where "input" is used without *
    // put into the next line

    if (character == 'b'){
      for( 
    it 9it it-- )
      
    cout << "Variable is " << *input << ' ' << it << endl;
    }
    Last edited: Jan 9, 2016
    NeonSturm, Jan 9, 2016
    Last edited by NeonSturm; at Jan 9, 2016
    #2

Share This Page