Thread: Not able to run this structure code in c

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    1

    Not able to run this structure code in c

    Code:
    #include <stdio.h>
    int main()
    {
    	struct stud
    	{ char name;
    	int rollno;
    	float marks;
    	
    	};
    	struct stud s1,s2,s3;
    
    		printf("enter name , roll no. and marks\n");
    	scanf("%c %d %f",&s1.name,&s1.rollno,&s1.marks);
    	scanf("%c %d %f",&s2.name,&s2.rollno,&s2.marks);
    	scanf("%c %d %f",&s3.name,&s3.rollno,&s3.marks);
    	
    		
    	printf("%c %d %f",s1.name,s1.rollno,s1.marks);
    	printf("%c %d %f",s2.name,s2.rollno,s2.marks);
    	printf("%c %d %f",s3.name,s3.rollno,s3.marks);
    	
    	float average;
    	average = ((s1.marks+s2.marks+s3.marks)/3);
    	printf("the average marks of students is %f",average);
    	
    		
    		return 0;
    		
    		}

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,498
    Code:
        scanf(" %c %d %f",&s1.name,&s1.rollno,&s1.marks);
        scanf(" %c %d %f",&s2.name,&s2.rollno,&s2.marks);
        scanf(" %c %d %f",&s3.name,&s3.rollno,&s3.marks);
    Put a space before each %c in scanf, if you want to read the next non-whitespace character.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C structure basic code not compiling
    By thagulf2017 in forum C Programming
    Replies: 1
    Last Post: 05-31-2017, 06:28 PM
  2. Structure Code
    By garcia1987 in forum C Programming
    Replies: 3
    Last Post: 10-06-2014, 07:02 PM
  3. help in data structure c++ code
    By caca in forum C++ Programming
    Replies: 8
    Last Post: 01-31-2011, 01:07 PM
  4. Rewrite code in structure way
    By ninety3gd in forum C Programming
    Replies: 3
    Last Post: 06-11-2009, 08:49 PM
  5. structure code help
    By Madshan in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2004, 12:51 AM

Tags for this Thread