(Beginner) Please help me with C languagecrying

Asked 6 days ago, Updated 6 days ago, 1 views

The problem is the title of report card output.

In the first line, the number of data n (3<=n<=100) and the output personnel m (1<=m<=n) are divided into spaces and entered.

From the second line, the student name and score (0100) are divided into spaces and entered.

However, the length of the name is up to 10 bytes.

Output : Outputs a list of the top m students.


The code I made is

#include <stdio.h>

#include <string.h>

struct student {
    char name[100];
    int score[100];

int main() {

    int n, m = 0;
    int tmp, tmp1 = 0;

    struct student s[100];

    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf("%s %d", &s[i].name, &s[i].score);    

    for (int i = 0; i < n; i++) {
        if (s[i].score > s[i + 1].score) {
            tmp = s[i].score;
            s[i].score = s[i + 1].score;
            s[i + 1].score = tmp;

            strcpy(tmp1, s[i].name);
            strcpy(s[i].name, s[i + 1].name);
            strcpy(s[i + 1].name, tmp1);

    for (int i = 0; i < m; i++) {
        printf("%s\n", s[i].name);

It's this. If you look back at the execution, Nothing pops up and it just turns off...I don't know where the problem is(Crying)


2022-09-20 15:36

1 Answers

system ("PAUSE") on the last line of main; write it down and run it

2022-09-20 15:36

If you have any answers or tips

© 2022 pinfo. All rights reserved.