Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Structures in c programming

  1. Jun 19, 2009 #1
    the foolowing program is to read inputed data and display them all at once but when i run it it asks for the first information and then runs the total program without asking for the input of other information.after that it doesnt respond and closes immediatelly.
    can someone help me and tells me whats wrong with my program?
    thanks for your help.

    struct database {
    char name;
    int phone_number,id_numb;
    struct database ident;
    printf("enter a name\n");
    printf("enter a phn numb\n");/* enter a phone number*/
    printf("enter the id_numb\n");/*enter an id number*/
    printf("the identity of %s is:\n",ident.name);/*displays the name*/
    printf("phone:%d id:%d \n",ident.phone_number,ident.id_numb);/*displays the phone number and the id number*/
  2. jcsd
  3. Jun 19, 2009 #2


    User Avatar
    Homework Helper

    the scanf("%c",...) is the issue. This reads a single character into the single character variable name. If you enter more than one character, scanf will attempt to handle those with the following scanf()'s.

    Perhaps you'd want to use a string, which will solve the problem:

    char name[128];

    scanf("%s", ident.name);

    printf( "... %s ...", ident.name);
  4. Jun 23, 2009 #3
    I saw where i was making an error.
    i corrected and while initialising the character i defined as an array and that way in the printf and scanf functions instead of using %c i used %s.after that the program is compiled and run without complications
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Structures programming Date
Data Structure Sep 18, 2016
Data structures (trees) Apr 21, 2016
General "Methods/Structures" in Programming May 22, 2015
Video lectures of Structure and Intepretation of Computer Programs Dec 21, 2008
Fortran program structuring Feb 26, 2007