0

Why can't i run this in visual studio?

#include <stdio.h> struct student { int roll; float percent; char name[20]; } s[100], temp; void main() { int i, j, n; printf("enter the no. of students: " ); scanf_s("%d", &n); for (i = 0; i < n; i++) { printf("\nstudent's Roll Number: "); scanf_s("%d", &s[i].roll); printf("\nstudent's Name: "); scanf_s("%s", &s[i].name); printf("\nStudent's percentage: "); scanf_s("%f", &s[i].percent); } for (i = 0; i < n; i++) { printf("\nROLL_NUMBER\tNAME\tPERCENTAGE\n\n\n"); printf("%d", s[i].roll); printf("\t%s", s[i].name); printf("\t%.1f", s[i].percent); } for (i = 0; i < n; i++) { for (j = 0; j < n - i - 1; j++) { if (s[j].percent < s[j + 1].percent) { temp = s[j]; s[j] = s[j + 1]; s[j + 1] = temp; } } } printf("In order"); printf("\nROLL_NUMBER\tNAME\tPERCENTAGE\n\n\n"); for (i = 0; i < n; i++) { printf("%d", s[i].roll); printf("\t%s", s[i].name); printf("\t%.1f", s[i].percent); } }

7th Oct 2021, 6:27 AM
Sumit Acharya
Sumit Acharya - avatar
1 Resposta
+ 2
It works but there are few mistakes. Use scanf instead of scanf_s, if you want to use scanf_s you need to insert buffer size too. That's why vs code displays an error. read : https://www.geeksforgeeks.org/scanf-fscanf-sscanf-scanf_s-fscanf_s-sscanf_s/
7th Oct 2021, 8:14 AM
Rusiru Rathmina
Rusiru Rathmina - avatar