Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Simple struct, c-program- somthing goes wrong

+1 vote
asked Nov 8, 2018 by okire (250 points)
edited Nov 8, 2018 by okire

If, int i = 5 and char ch = A - only 5 prints out, why not char too?

**********************************

#include <stdio.h>

  struct s_type {

    int i;

    char ch;

    } s;

int main(void) {

  printf("Enter an integer\n");

  scanf("%d", &s.i);

  printf("Enter a character\n");

  scanf("%c", &s.ch);

  printf("\n%d %c", s.i, s.ch);

  return 0;

}

************************************

2 Answers

0 votes
answered Nov 9, 2018 by anonymous

Use ---  scanf("%s", &s.ch);

commented Nov 9, 2018 by okire (250 points)
Oh, thanks :)
0 votes
answered Nov 12, 2018 by murfo

#include <stdio.h>
struct s_type {
  int i;
  char ch;
} s;

int main(void) {
  printf("Enter an integer\n");
  scanf("%d", &s.i);
  getchar();
  printf("Enter a character\n");
  scanf("%c", &s.ch);
  getchar();
  printf("\n%d %c", s.i, s.ch);
  return 0;
}

commented Nov 12, 2018 by okire (250 points)
(y) -  thanks!!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...