Thread: structure giving weird output

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User bluetxxth's Avatar
    Join Date
    Feb 2010
    Location
    sweden
    Posts
    43

    structure giving weird output

    Hello there,


    I have written a structure as an example and I am having trouble compiling it... I don't see what is wrong with it I think it has to do with some other thing but I am not sure...

    The code is as follows:

    Code:
    /*
     * test1.c
     *
     *  Created on: Feb 9, 2010
     *      Author
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
    
    	struct employee {
    		char name[30];
    		char address[100];
    		int age;
    		float salary;
    	} emp1;
    
    
    
    	printf("Enter the name of the employee: ");
    	scanf("%s", emp1.name);
    	printf("Enter the address of the employee: ");
    	scanf("%s", emp1.address);
    	printf("Enter the age of the employee: ");
    	scanf("%d", &emp1.age);
    	printf("Enter the salary of the employee: ");
    	scanf("%f", &emp1.salary);
    
    
    
    	printf("the age of emp1 is: %s\n", emp1.name);
    	printf("the age of emp1 is: %s\n", emp1.address);
    	printf("the age of emp1 is: %d\n", emp1.age);
    	printf("the salary of emp1 is: %f\n", emp1.salary);
    
    
    
    
    	return 0;
    }

    and I get this as an output:


    Enter the name of the employee: Enter the address of the employee: Enter the age of the employee: Enter the salary of the employee: the age of emp1 is: ץ0wM
    the age of emp1 is: '
    the age of emp1 is: 77
    the salary of emp1 is: 0.000000


    Please can anyone help me? is there something wrong with the code?




    -------------------------------------------------

    windows vista x64 ultimate
    eclipse-SDK-3.5.1-win32
    mingw-w32-bin_i686-mingw_20100123_sezero
    MSYS-1.0.11
    Last edited by bluetxxth; 02-14-2010 at 01:52 PM. Reason: missing words

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDE for C embedded advanced editing
    By Undici77 in forum Tech Board
    Replies: 32
    Last Post: 01-16-2010, 05:17 PM
  2. Weird Output when I compile?
    By unejam2005 in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2005, 01:46 AM
  3. Weird special character text after output
    By Dan17 in forum C++ Programming
    Replies: 13
    Last Post: 12-07-2005, 03:41 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM