从文件中读取15个整数将它们存储在数组中

从文件中读取15个整数mydata.txt,将它们存储在数组中,按升序对数组中的数字进行排序,最后将排序后的数字写入名为mysorted.txt.的文件夹

从文件中读取15个整数mydata.txt

img



#include <stdio.h>
int main()
{
    int a[6];
    FILE* fpread;
    fpread = fopen("mydata.txt", "r");
    if (fpread == NULL)
    {
        printf("file is error.");
        return -1;
    }

    
        for (int j = 0; j < 6; j++)
        {
            fscanf(fpread, "%d", &a[j]);
        }
    
    fclose(fpread);

        for (int j = 0; j < 6; j++)
        {
            printf("%d\t",a[j]);
        }
        printf("\n");

    return 0;
}