منتدي الشباب

هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

هذا المنتدي يسعى للوصول الى اظهار مواهب الطلاب وخلق بيئة ترفيهية مفيدة

مفــــــــــــاجأة الموسمlanregionألعاب شبكة_ألعاب كمبيوتر ومكتبة ميديا_صيانة بى سى ولاب توب _تصميم مواقع انترنتت : 0918265887 _ 0922302527الخرطوم 2 سوق نمرة 2 شارع عبد المنعم مقابل ريل بيرقر

    Input & Output Function In C Language

    Admin
    Admin
    Admin


    عدد الرسائل : 45
    الموقع : www.fasaha2005.webs.com
    تاريخ التسجيل : 19/02/2009

    Input & Output Function In C Language Empty Input & Output Function In C Language

    مُساهمة  Admin الجمعة فبراير 27, 2009 3:36 am




    Input :

    In any programming language input means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement.
    Output :

    In any programming language output means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output required data.
    Here we will discuss only one input function and one putput function just to understand the meaning of input and output.
    The basic input function:-

    * printf( ) function
    This is one of the most frequently used functions in C for output. It can be used for writing chars, ints, floats, as well as string. The general form of printf () is as follows:

    printf ("……. % ", );



    Example:
    #include

    main()
    {
    int dec = 5;
    char str[] = "abc";
    char ch = 's';
    float pi = 3.14;

    printf("%d %s %f %c\n", dec, str, pi, ch);
    }
    The output of the above would be:
    5 abc 3.140000 c
    Here %d is being used to print an integer, %s is being usedto print a string, %f is being used to print a float and %c is being used to print a character.
    * Other input function:-
    Are
    Input
    Data type Function Purpose
    Char


    String getch()


    getche()


    Fgethar()


    getchar()

    gets() Gets a character from the keyboard as soon as it typed, no need to hit Enter
    Similar to getch(),except echoes the character on the screen.
    Gets the character & echoes it on the screen, requires Enter Key to be hit
    A macro, works similar to fgetchar.

    Accept a string until Enter Key hit.
    The basic output function:-
    * scanf( ) function
    This is the function which can be used to to read an input from the command line.
    Try following program to understand scanf() function. It can be used for reading chars, ints, floats, as well as string. The general form of scanf () is as follows:
    scanf ("% ",& );


    Example:
    #include

    main()
    {
    int x;
    int args;

    printf("Enter an integer: ");
    if (( args = scanf("%d", &x)) == 0) {
    printf("Error: not an integer\n");
    } else {
    printf("Read in %d\n", x);
    }
    }
    Here %d is being used to read an integer value and we are passing &x to store the vale read input. Here &indicates the address of variavle x.
    This program will prompt you to enter a value. Whatever value you will enter at command prompt that will be output at the screen using printf() function. If you eneter a non-integer value then it will display an error message.
    Enter an integer: 20
    Read in 20

    * other output function:-

    Are

    Output
    Purpose Function Data type
    Prints the character on the screen.

    Prints the character on the screen.

    A macro, works similar to putch( ) & function.

    Outputs a string to the screen. Putch( )


    Fputchar( )


    Putchar( )


    Puts( )
    Char



    String

      مواضيع مماثلة

      -

      الوقت/التاريخ الآن هو الأربعاء مايو 15, 2024 12:22 pm