0

My programm wont let me input all the data I need. And when I try to display them it won't even use the data that I could input. Please help me and sorry for my bad English it is not my native language, that's why all the data is in Slovene. Thanks for any help that I will get.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student 

       char vpisna_st[8]; 
       char ime[20];
       char priimek[20];
       int starost;

}stud;


int main()
{
  struct student stud;  
  printf("Vnesite vase podatke. \n");
  printf("Vpisna stevilka: ");
  scanf("%c",&stud.vpisna_st); 
  printf("Ime: ");
  scanf("%c",&stud.ime);
  printf("Priimek: ");
  scanf("%c",&stud.priimek);
  printf("Starost: ");
  scanf("%d",&stud.starost);


  printf("Student je:\n vpisna st: %c, \n ime: %c, \n priimek: %c, \n starost: %d \n", stud.vpisna_st,stud.ime,stud.priimek,stud.starost);  
  system("PAUSE");  
  return 0;
}{
2
Contributors
2
Replies
16
Views
3 Years
Discussion Span
Last Post by Aljaz
1

"%c" only gets one character from the keyboard. I see the structure contains several character arrays, so "%s" is probably more appropriate. Also, it's not necessary to use & before character arrays because they are already passed as pointer by default. For example

scanf("%s",stud.vpisna_st);

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.