zame
zame

Reputation: 13

why does my first input does not displays?

#include <stdio.h>

int main()
{
    char name[100], subject1[100], subject2[100], stdsignature[100], advisorsignature[100];
    char code1[7], code2[7], stdID[7];
    int credit1, credit2, total;

    printf ("Universiti of Gambang \n");
    printf ("Subjects Registration Form \n");

    printf ("Name: ");
    fflush (stdin);
    fgets ( name , 100 , stdin );

    printf ("Student ID: ");
    fflush(stdin);
    scanf ("%s",&stdID);

    printf ("Total subjects for every semester must be 2 \nSubject name 1: ");
    fflush(stdin);
    scanf ("%s",&subject1);

    printf ("Subject code 1: ");
    scanf ("%s",&code1);

    printf ("Credit 1: ");
    scanf ("%d",&credit1);

    printf ("Subject name 2: ");
    fflush(stdin);
    scanf ("%s",&subject2);

    printf ("Subject code 2: ");
    scanf ("%s",&code2);

    printf ("Credit 2:");
    scanf ("%d",&credit2);

    total= credit1 + credit2;

    printf ("Total %d \n",total);


    printf ("Advisor's signature ");
    fflush(stdin);
    scanf ("%s",&advisorsignature);

    printf ("                                         Universiti of Gambang \n");
    printf ("                                       Subjects Registration Form \n");

    printf ("================================================================================================================ \n");

    printf ("Name: %s \n",name);
    printf ("Student ID: %s \n",stdID);
    printf ("Total subject: 2 \n");

    printf ("---------------------------------------------------------------------------------------------------------------\n");
    printf ("     Subject name                            Subject code                            Credit                    \n");
    printf ("          %s                                       %s                                 %d \n",subject1 ,code1,credit1);
    printf ("          %s                                       %s                                 %d \n",subject2 ,code2,credit2);
    printf ("---------------------------------------------------------------------------------------------------------------\n");
    printf ("     Total credits                                                                    %d \n ",total             );

    printf ("Academic Advisor: %s \n",advisorsignature);

    return 0;
}
.

I do not know where does my first input goes. Please help me.
enter image description here

Upvotes: 0

Views: 129

Answers (3)

zame
zame

Reputation: 13

#include <stdio.h>

int main()
{
    char name[100], subject1[100], subject2[100], stdsignature[100], advisorsignature[100];
    char code1[50], code2[50], stdID[50];
    int credit1, credit2, total;

    printf ("Universiti of Gambang \n");
    printf ("Subjects Registration Form \n");

    printf ("Name: ");
    gets ( name );
    fflush (stdin);

    printf ("Student ID: ");
    scanf (" %s",&stdID);
    fflush(stdin);

    printf ("Total subjects for every semester must be 2 \nSubject name 1: ");
    fflush(stdin);
    scanf ("%s",&subject1);

    printf ("Subject code 1: ");
    fflush(stdin);
    scanf ("%s",&code1);

    printf ("Credit 1: ");
    scanf ("%d",&credit1);

    printf ("Subject name 2: ");
    fflush(stdin);
    scanf ("%s",&subject2);

    printf ("Subject code 2: ");
    fflush(stdin);
    scanf ("%s",&code2);

    printf ("Credit 2:");
    scanf ("%d",&credit2);

    total= credit1 + credit2;

    printf ("Total %d \n",total);

    printf ("Student's signature ");
    fflush(stdin);
    scanf ("%s",&stdsignature);

    printf ("Advisor's signature ");
    fflush(stdin);
    scanf ("%s",&advisorsignature);

    printf ("                                         Universiti of Gambang \n");
    printf ("                                       Subjects Registration Form \n");

    printf ("================================================================================================================ \n");

    printf ("Name : %s \n",name);
    printf ("Student ID: %s \n",stdID);
    printf ("Total subject: 2 \n");

    printf ("---------------------------------------------------------------------------------------------------------------\n");
    printf ("     Subject name                            Subject code                            Credit                    \n");
    printf ("          %s                                       %s                                 %d \n",subject1 ,code1,credit1);
    printf ("          %s                                       %s                                 %d \n",subject2 ,code2,credit2);
    printf ("---------------------------------------------------------------------------------------------------------------\n");
    printf ("     Total credits                                                                    %d \n ",total             );

    printf ("Academic Advisor: %s \n",advisorsignature);

    return 0;
}

So, I manage to solve the missing input of mine by manipulate some of the codes. thanks for your responds gais. enter image description here

Upvotes: 0

Akshay Patole
Akshay Patole

Reputation: 474

Your program gives warnings mentioned by santhosh.

Two things,

1) You haven't provided & while taking integer input for int variable credit1 and credit2. Use & for integer variables in scanf,

scanf ("%d",&credit1); .. scanf ("%d",&credit2);

2) You don't need to provide & while taking character inputs. In C, string is an array of characters. When we pass an array then it actually points to the address of the first element of an array.

So there is no need to use "&" in scanf while taking inputs in an array.

Regarding your issue, Your program gives expected output. Can you please provide more details ?

Upvotes: 1

santhosh reddy
santhosh reddy

Reputation: 66

As BLUEPIXY mentioned, this code snippet gives output, except that there are few warnings. Below are more details,

In function ‘main’:
ex.c:30:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[7]’ [-Wformat=]
 scanf ("%s",&stdID);
 ^
ex.c:34:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100]’ [-Wformat=]
 scanf ("%s",&subject1);
 ^
ex.c:37:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[7]’ [-Wformat=]
 scanf ("%s",&code1);
 ^
ex.c:44:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100]’ [-Wformat=]
 scanf ("%s",&subject2);
 ^
ex.c:47:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[7]’ [-Wformat=]
 scanf ("%s",&code2);
 ^
ex.c:59:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100]’ [-Wformat=]
 scanf ("%s",&advisorsignature);

Upvotes: 0

Related Questions