为什么我的程序输出内存地址?

时间:2014-03-30 23:52:00

标签: c function memory-address

该计划的目标是使用功能创建输入学生ID及其考试成绩的表格。然后将测试等级转换为字母等级。我的问题是程序输出内存而不是输入的数字。我知道我在某个地方犯了一个错误,但我似乎无法弄明白。任何帮助是极大的赞赏。

#include <stdio.h>

#define NUM 12

void obtain_id_scores (int [], int []);
void get_letter_grade (char [], int []);
void display_results (int [], int [], char []);

int main (void)
{
    int student_id [50];
    int test_score [50];
    char letter_grade [50];

    obtain_id_scores (student_id, test_score);
    get_letter_grade (letter_grade, test_score);
    display_results (student_id, test_score, letter_grade);

    return 0;
} /* End Main. */


void obtain_id_scores (int student_id [], int test_score [])
{
    int x;

    for (x = 1; x <= NUM; ++x)
    {
        printf (" Enter student ID and test grade: ");
        scanf ("%s %s", &student_id [x], &test_score [x]);
        fflush (stdin);
    }   
}


void get_letter_grade (char letter_grade [], int test_score [])
{
    int x;

    for (x = 1; x <= NUM; ++x)
    {
        if (test_score [x] > 100)
        letter_grade [x] = 'N';
        else if (test_score [x] >= 90)
        letter_grade [x] = 'A';
        else if (test_score [x] >= 80)
        letter_grade [x] = 'B';
        else if (test_score [x] >= 70)
        letter_grade [x] = 'C';
        else if (test_score [x] >= 60)
        letter_grade [x] = 'D';
        else
        letter_grade [x] = 'F';
    }
}

void display_results (int student_id [], int test_score [], char letter_grade [])
{
    int x;

    /* Display Results */

    printf ("           Student Grade Report\n");
    printf ("          ---------------------\n\n");
    printf ("   ID        TEST SCORE   LETTER GRADE\n");

    /* Display all IDs, test scores, and letter grades. */

    for (x = 1; x < NUM; ++x)
    {
        printf ("%6i       %6i     %8c\n", student_id[x], test_score[x], letter_grade[x]);      
        }
}

1 个答案:

答案 0 :(得分:1)

scanf ("%s %s" ..将输入的文本存储为字符串,然后将它们存储到int s。

使用

scanf ("%d %d" ...

接受输入为数字。