c programming help

sandun36

Well-known member
  • Jan 28, 2009
    1,731
    440
    113
    somebody pls tell me how to take a input of individual number strings using scanf function or anything else in c.
    input should be appear as
    1 2 3 4 5 6 7 8 9 10
    if u have any suggestion pls post me.i'll be very grateful to u!:(
     

    ins

    Member
    Dec 21, 2006
    403
    6
    0
    include all headers and stuff...

    for(int i=1;i<=10;i++)
    {
    cout<<i<<" "<<;
    }

    return 0;
    }
     

    pga

    Well-known member
  • Oct 4, 2006
    3,965
    914
    113
    somebody pls tell me how to take a input of individual number strings using scanf function or anything else in c.
    input should be appear as
    1 2 3 4 5 6 7 8 9 10
    if u have any suggestion pls post me.i'll be very grateful to u!:(

    check this,
    http://www.daniweb.com/forums/post716510.html#post716510

    #include <stdio.h>

    int main(void) {
    char str[7] = { '\0' };
    int i = 0;
    char ch;

    /* everything from imput will be read */
    while ((scanf("%c", &ch) == 1) && ch != '\n') {
    if (i < 6) { /* keep only six characters from input */
    str = ch;
    ++i;
    }
    }

    printf("%s", str);
    return 0;
    }
     

    pga

    Well-known member
  • Oct 4, 2006
    3,965
    914
    113
    පැටියා;5663972 said:
    ade kohomada c install karanne???

    install a C compiler. if you use ubuntu or like linux distro you will get gcc compiler already installed
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    You have to use an array machan... :)

    #include <stdio.h>

    Code:
    void main()
    {
    int numbers[10];
    int i;
    
            for (i=0; i < 10; i++)
           {
              printf( "Enter number %d : ", i+1);
              scanf("%d",numbers[i]);
          }
    
    }
     

    sandun36

    Well-known member
  • Jan 28, 2009
    1,731
    440
    113
    machan okedi output ekai input ekai labenne mehema
    Enter number 1
    Enter number 2
    Enter number 3
    ...
    mata ona oka neme
    enter number 1 2 3 4 5 6 7 ... vidhiye ekak
     

    sandun36

    Well-known member
  • Jan 28, 2009
    1,731
    440
    113
    machan oka array valata hariyanne naha. also for simple purposes also your command is
    wrong .between %d you can't use commas