IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> c primer plus(第六版) 第十三章答案(vscode编译运行通过) -> 正文阅读

[开发工具]c primer plus(第六版) 第十三章答案(vscode编译运行通过)

在这里插入图片描述在这里插入图片描述
在这里插入图片描述
1.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 256

char *s_gets(char arr[], int n);
int main(int argc, char *argv[])
{
    int ch;
    FILE *fp;
    char arr[SIZE];
    unsigned long count = 0;
    puts("Please input filename: ");
    s_gets(arr, SIZE);


   if((fp = fopen(arr,"r")) == NULL)
   {
       printf("Can't open %s\n",argv[1]);
       exit(EXIT_FAILURE);
   }
   while((ch = getc(fp)) != EOF)
   {
       putc(ch,stdout);
       count++;
   }
   putchar('\n');
   fclose(fp);
   printf("File %s has %lu characters\n",arr,count);
    system("pause");
    return 0;
}

char *s_gets(char arr[], int n)
{
    char *ret1;

    ret1 = fgets(arr,n,stdin);
    if(ret1)
    {
        char * ret2;
        ret2 = strchr(arr, '\n');
        if(ret2)
        {
            *ret2 = '\0';
        }
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret1;
}

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 512


int main(int argc, char *argv[])
{
    size_t ch;
    FILE *fp1;
    FILE *fp2;
    char buff[SIZE];

   if((fp1 = fopen(argv[1],"rb")) == NULL)
   {
       printf("Can't open %s\n",argv[1]);
       exit(EXIT_FAILURE);
   }
   if((fp2 = fopen(argv[2],"wb")) == NULL)
   {
       printf("Can't open %s\n",argv[2]);
       exit(EXIT_FAILURE);
   }
   while((ch = fread(buff, sizeof(char), SIZE, fp1)) >0)
   {
       fwrite(buff, sizeof(char), ch, fp2);
   }
   if(fclose(fp1) != 0)
   {
       printf("Can't close %s it", argv[1]);
   }
   if(fclose(fp2) != 0)
   {
        printf("Can't close %s it", argv[2]);
   }
    return 0;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define SIZE 512

char *s_gets(char arr[], int n);
int main(int argc, char *argv[])
{
    char ch;
    FILE *fp;
    char buff[SIZE];
    long last, count;
    
    puts("Please input the file's name: ");
    s_gets(buff, SIZE);
   if((fp = fopen(buff,"r+")) == NULL)
   {
       printf("Can't open %s\n",buff);
       exit(EXIT_FAILURE);
   }

    last = ftell(fp);
    while((ch = getc(fp)) != EOF)
    {
        fseek(fp, -1L, SEEK_CUR);
        ch = toupper(ch);
        putc(ch, fp);
        fseek(fp, 0, SEEK_CUR); 
    }

   if(fclose(fp) != 0)
   {
       printf("Can't close %s it", argv[1]);
   }
    return 0;
}

char *s_gets(char arr[], int n)
{
    char *ret1;

    ret1 = fgets(arr,n,stdin);
    if(ret1)
    {
        char * ret2;
        ret2 = strchr(arr, '\n');
        if(ret2)
        {
            *ret2 = '\0';
        }
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret1;
}


#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define SIZE 512

int main(int argc, char *argv[])
{
    char ch;
    FILE *fp;
    
    for(int i = 1; i < argc ; i++)
    {
         if((fp = fopen(argv[i],"r")) == NULL)
        {
            printf("Can't open %s\n",argv[i]);
            exit(EXIT_FAILURE);
        }
        while((ch = getc(fp)) != EOF)
        {
            putc(ch, stdout);
        }
         if(fclose(fp) != 0)
        {
            printf("Can't close %s it", argv[i]);
        }
    }
    return 0;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define BUFSIZE 4096
void append(FILE *source, FILE *dest);

int main(int argc, char **argv)
{
    FILE *fa, *fs;
    int files = 0;

    int ch;

    if((fa = fopen(argv[1],"a+")) == NULL)
    {
        fprintf(stderr,"Can't open %s\n",argv[1]);
        exit(EXIT_FAILURE);
    }
    if(setvbuf(fa,NULL,_IOFBF,BUFSIZE) != 0)
    {
        fputs("Can't create output buffer\n",stderr);
        exit(EXIT_FAILURE);
    }
    
    for( int i = 2; i < argc; i++)
    {
        if(strcmp(argv[1],argv[i]) == 0)
            fputs("Can't append file to itself\n",stderr);
        else if((fs = fopen(argv[i],"r")) == NULL)
            fprintf(stderr,"Cann't open %s\n",argv[i]);
        else
        {
            if(setvbuf(fs,NULL,_IOFBF,BUFSIZE) != 0)
            {
                fputs("Can't create inupt buffer\n",stderr);
                continue;
            }
            append(fs,fa);
            if(ferror(fs) != 0)
                fprintf(stderr,"Error in reading file %s.\n",argv[i]);
            if(ferror(fa) != 0)
                fprintf(stderr,"Error in writing file %s.\n",argv[1]);
            fclose(fs);
            files++;
            printf("File %s appended.\n",argv[i]);
        }    
    }
    printf("Done appending. %d files appended.\n",files);
    rewind(fa);
    printf("%s contents:\n",argv[1]);
    while((ch = getc(fa)) != EOF)
        putchar(ch);
    puts("\nDone displaying.");
    fclose(fa);
    system("pause");
    return 0;
}

void append(FILE *source, FILE *dest)
{
    size_t bytes;
    static char temp[BUFSIZE];

    while((bytes = fread(temp,sizeof(char),BUFSIZE,source)) > 0)
        fwrite(temp,sizeof(char),bytes,dest);
}

char * s_gets(char *st,int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st,n,stdin);
    if(ret_val)
    {
        find = strchr(st,'\n');
        if(find)
            *find = '\0';
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret_val;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define LEN 40

char *s_gets(char arr[], int n);

int main(int argc, char *argv[])
{
   FILE *in, *out;
   int ch;
   char name[LEN];
   int count = 0;

   printf("Please input file's name: ");
   s_gets(name, LEN - 8);

   if((in = fopen(name,"r")) == NULL)
   {
       fprintf(stderr,"I couldn,t open the file \"%s\"\n",name);
       exit(EXIT_FAILURE);
   }
   strcat(name,"red.txt");
   if((out = fopen(name,"w")) == NULL)
   {
       fprintf(stderr,"Can't creat output file.\n");
       exit(3);
   }
   while((ch = getc(in)) != EOF)
        if(count++ % 3 == 0)
            putc(ch,out);
    if(fclose(in) != 0 || fclose(out) != 0)
        fprintf(stderr,"Error in closing files\n");
    system("pause");
    return 0;
}

char * s_gets(char *st,int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st,n,stdin);
    if(ret_val)
    {
        find = strchr(st,'\n');
        if(find)
            *find = '\0';
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret_val;
}

7.a

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define LEN 40

char *s_gets(char arr[], int n);

int main(int argc, char *argv[])
{
   FILE *fp1, *fp2;
   int ch1;
   int ch2;
   char name1[LEN];
   char name2[LEN];
   int count = 0;

   printf("Please input first file's name: ");
   s_gets(name1, LEN);
   if((fp1 = fopen(name1,"r")) == NULL)
   {
       fprintf(stderr,"I couldn,t open the file \"%s\"\n",name1);
       exit(EXIT_FAILURE);
   }
   printf("Please input second file's name: ");
   s_gets(name2, LEN);
   if((fp2 = fopen(name2,"r")) == NULL)
   {
       fprintf(stderr,"I couldn,t open the file \"%s\"\n",name2);
       exit(EXIT_FAILURE);
   }
   ch1 = getc(fp1);
   ch2 = getc(fp2);
   while(ch1 != EOF || ch2 != EOF)
   {
       while(ch1 != EOF && ch1 != '\n')
       {
           putchar(ch1);
           ch1 = getc(fp1);
       }
       if(ch1 == '\n')
       {
           putchar(ch1);
           ch1 = getc(fp1);
       }
       while(ch2 != EOF && ch2 != '\n')
       {
           putchar(ch2);
           ch2 = getc(fp2);
       }
       if(ch2 == '\n')
       {
           putchar(ch2);
           ch2 = getc(fp2);
       }
   }
    if(fclose(fp1) != 0 || fclose(fp2) != 0)
        fprintf(stderr,"Error in closing files\n");
    return 0;
}

char * s_gets(char *st,int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st,n,stdin);
    if(ret_val)
    {
        find = strchr(st,'\n');
        if(find)
            *find = '\0';
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret_val;
}

7.b

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define LEN 40

char *s_gets(char arr[], int n);

int main(int argc, char *argv[])
{
   FILE *fp1, *fp2;
   int ch1;
   int ch2;
   char name1[LEN];
   char name2[LEN];
   int count = 0;

   printf("Please input first file's name: ");
   s_gets(name1, LEN);
   if((fp1 = fopen(name1,"r")) == NULL)
   {
       fprintf(stderr,"I couldn,t open the file \"%s\"\n",name1);
       exit(EXIT_FAILURE);
   }
   printf("Please input second file's name: ");
   s_gets(name2, LEN);
   if((fp2 = fopen(name2,"r")) == NULL)
   {
       fprintf(stderr,"I couldn,t open the file \"%s\"\n",name2);
       exit(EXIT_FAILURE);
   }
   ch1 = getc(fp1);
   ch2 = getc(fp2);
   while(ch1 != EOF || ch2 != EOF)
   {
       while(ch1 != EOF && ch1 != '\n')
       {
           putchar(ch1);
           ch1 = getc(fp1);
       }
       if(ch1 == '\n')
       {
           if(ch2 == EOF)
           {
               putchar('\n');
           }
           else
           {
               putchar(' ');
           }
           ch1 = getc(fp1);
       }
       while(ch2 != EOF && ch2 != '\n')
       {
           putchar(ch2);
           ch2 = getc(fp2);
       }
       if(ch2 == '\n')
       {
           putchar(ch2);
           ch2 = getc(fp2);
       }
   }
    if(fclose(fp1) != 0 || fclose(fp2) != 0)
        fprintf(stderr,"Error in closing files\n");
    return 0;
}

char * s_gets(char *st,int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st,n,stdin);
    if(ret_val)
    {
        find = strchr(st,'\n');
        if(find)
            *find = '\0';
        else
        {
            while(getchar() != '\n')
                continue;
        }
        
    }
    return ret_val;
}

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define MAX 41

int main(int argc, char *argv[])
{
    FILE *fp;
    char words[MAX];
    int count;

    if((fp = fopen("wordy.txt","a+")) == NULL)
    {
        fprintf(stdout,"Can't open \"wordy\" file.\n");
        exit(EXIT_FAILURE);
    }

    puts("Enter words to add to the file;press the #");
    puts("key at the beginning of a line to terminate.");
    while(fscanf(fp,"%d%40s", &count,words) == 2);
    while((fscanf(stdin,"%40s",words) == 1) && (words[0] != '#'))
    {
        count++;
        fprintf(fp,"%d%s\n", count,words);
    }
    puts("File contents:");
    rewind(fp);
    while(fscanf(fp,"%s",words) == 1)
        puts(words);
    puts("Done!");
    if(fclose(fp) != 0)
        fprintf(stderr,"Error closing file\n");
    system("pause");
    return 0;
}                                                                                                                                                                                                                                                                                                
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define MAX 41

int main(int argc, char *argv[])
{
    FILE *fp;
    char words[MAX];
    int count;

    if((fp = fopen("wordy.txt","a+")) == NULL)
    {
        fprintf(stdout,"Can't open \"wordy\" file.\n");
        exit(EXIT_FAILURE);
    }

    puts("Enter words to add to the file;press the #");
    puts("key at the beginning of a line to terminate.");
    while(fscanf(fp,"%d%40s", &count,words) == 2);
    while((fscanf(stdin,"%40s",words) == 1) && (words[0] != '#'))
    {
        count++;
        fprintf(fp,"%d%s\n", count,words);
    }
    puts("File contents:");
    rewind(fp);
    while(fscanf(fp,"%s",words) == 1)
        puts(words);
    puts("Done!");
    if(fclose(fp) != 0)
        fprintf(stderr,"Error closing file\n");
    system("pause");
    return 0;
}                                                                                                                                                                                                                                                                                               
在这里插入代码片
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define SLEN 81


int main(int argc, char **argv)
{
    FILE * fp;
    long pos = 0;
    char name[SLEN];
    int ch;

    puts("Please input the file's name: ");
    scanf("%80s", name);
    if((fp = fopen(name,"r")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", name);
        exit(EXIT_FAILURE);
    }
    printf("Please input the file's position: ");
    while((scanf("%ld", &pos) == 1) && (pos >=0))
    {
        fseek(fp, pos, SEEK_SET);
        while(((ch = fgetc(fp)) != EOF) && ch != '\n')
        {
            putc(ch, stdout);
        } 
        putchar('\n');
        printf("Please input the file's position: ");
    }
    if(fclose(fp) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", name);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define SLEN 81


int main(int argc, char **argv)
{
    FILE * fp;
    char str[SLEN];

    if(argc != 3)
    {
        fprintf(stderr, "Error, The parameter isn't right.\n");
        exit(EXIT_FAILURE);
    }
    if((fp = fopen(argv[2],"r")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[2]);
        exit(EXIT_FAILURE);
    }

    while(fgets(str, SLEN - 1, fp) != NULL)
    {
        if(strstr(str, argv[1]) != NULL)
        {
            fputs(str, stdout);
        }
    }
    if(fclose(fp) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[2]);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define SLEN 81
#define LEVELS 10
#define ROW 20
#define LINE 30
const char trans[LEVELS + 1] = " .':~*=&%#";


int main(int argc, char **argv)
{
    FILE * fp1, *fp2;
    char str[SLEN];
    int num;
    int arr1[ROW][LINE];
    char arr2[ROW][LINE+1];

    if(argc != 3)
    {
        fprintf(stderr, "Error, The parameter isn't right.\n");
        exit(EXIT_FAILURE);
    }
    if((fp1 = fopen(argv[1],"r")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    if((fp2 = fopen(argv[2],"w")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[2]);
        exit(EXIT_FAILURE);
    }
    for(int i = 0; i < ROW; i++)
    {
        for(int j = 0; j < LINE; j++)
        {
            fscanf(fp1, "%d",&num);
            arr1[i][j] = num;
        }
    }
    for(int i = 0; i < ROW; i++)
    {
        for(int j = 0; j <= LINE; j++)
        {
            if(j == LINE)
            {
                arr2[i][j] = '\0';
            }
            else
            {
                arr2[i][j] = trans[arr1[i][j]];
            }
        }
    }
    for(int i = 0; i < ROW; i++)
    {
        puts(arr2[i]);
    }
    for(int i = 0; i < ROW; i++)
    {
        for(int j = 0; j <= LINE; j++)
        {
            if(j == LINE)
            {
                fprintf(fp2, "\n");
            }
            else
            {
                fprintf(fp2, "%c", arr2[i][j]);
            }
        }
    }
    if(fclose(fp1) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[1]);
    }
    if(fclose(fp2) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[2]);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define SLEN 81
#define LEVELS 10
#define ROW 20
#define LINE 30
const char trans[LEVELS + 1] = " .':~*=&%#";

void getIntData(int row, int line, int arr1[row][line], FILE *fp)
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < line; j++)
        {
            fscanf(fp, "%d",&arr1[i][j]);
        }    
    }
}

void tranData(int row, int line, int arr1[row][line], char arr2[row][line + 1])
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j <= line; j++)
        {
            if(j == line)
            {
                arr2[i][j] = '\0';
            }
            else
            {
                arr2[i][j] = trans[arr1[i][j]];
            }
        }
    }
}

void showPicture(int row, int line,char arr[row][line+1])
{
    for(int i = 0; i < row; i++)
    {
        puts(arr[i]);
    }
}

void showInFile(int row, int line, char arr1[row][line], FILE *fp)
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j <= line; j++)
        {
            if(j == line)
            {
                fprintf(fp, "\n");
            }
            else
            {
                fprintf(fp, "%c", arr1[i][j]);
            }
        }
    }
}

int main(int argc, char **argv)
{
    FILE * fp1, *fp2;
    char str[SLEN];
    int num;
    int row = 20, line = 30;
    int arr1[row][line];
    char arr2[row][line+1];

    if(argc != 3)
    {
        fprintf(stderr, "Error, The parameter isn't right.\n");
        exit(EXIT_FAILURE);
    }
    if((fp1 = fopen(argv[1],"r")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    if((fp2 = fopen(argv[2],"w")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[2]);
        exit(EXIT_FAILURE);
    }
    getIntData(row, line, arr1, fp1);
    tranData(row, line, arr1, arr2);
    showPicture(row, line, arr2);
    showInFile(row, line, arr2, fp2);
    if(fclose(fp1) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[1]);
    }
    if(fclose(fp2) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[2]);
    }
    return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define SLEN 81
#define LEVELS 10
#define ROW 20
#define LINE 30
const char trans[LEVELS + 1] = " .':~*=&%#";

void getIntData(int row, int line, int arr1[row][line], FILE *fp)
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < line; j++)
        {
            fscanf(fp, "%d",&arr1[i][j]);
        }    
    }
}

void tranData(int row, int line, int arr1[row][line], char arr2[row][line + 1])
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j <= line; j++)
        {
            if(j == line)
            {
                arr2[i][j] = '\0';
            }
            else
            {
                arr2[i][j] = trans[arr1[i][j]];
            }
        }
    }
}

void showPicture(int row, int line,char arr[row][line+1])
{
    for(int i = 0; i < row; i++)
    {
        puts(arr[i]);
    }
}

void showInFile(int row, int line, char arr1[row][line], FILE *fp)
{
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j <= line; j++)
        {
            if(j == line)
            {
                fprintf(fp, "\n");
            }
            else
            {
                fprintf(fp, "%c", arr1[i][j]);
            }
        }
    }
}

void dealData(int row, int line, int arr[row][line])
{
    for(int i = 0; i < row; i++)
    {
        for(int k = 0; k < line; k++)
        {
            if(i == 0 && k == 0)
            {
                if(abs(arr[i][k] - arr[0][1]) > 1 && abs(arr[i][k] - arr[1][0]) > 1)
                {
                    arr[i][k] =  (arr[0][1] + arr[1][0]) / 2;
                }
            }
            else if(i == 0 && k == 29)
            {
                if(abs(arr[i][k] - arr[0][28]) > 1 && abs(arr[i][k] - arr[1][29]) > 1)
                {
                    arr[i][k] =  (arr[0][28] + arr[1][29]) / 2;
                }
            }
            else if(i == 19 && k == 0)
            {
                if(abs(arr[i][k] - arr[18][0]) > 1 && abs(arr[i][k] - arr[19][1]) > 1)
                {
                    arr[i][k] =  (arr[18][0] + arr[19][1]) / 2;
                }
            }
            else if(i == 19 && k == 29)
            {
                if(abs(arr[i][k] - arr[18][29]) > 1 && abs(arr[i][k] - arr[19][28]) > 1)
                {
                    arr[i][k] =  (arr[18][29] + arr[19][28]) / 2;
                }
            }
            else if(i == 0)
            {
                if(abs(arr[i][k] - arr[i][k-1]) > 1 && abs(arr[i][k] - arr[i][k+1]) > 1 && abs(arr[i][k] - arr[i+1][k]) > 1)
                {
                    arr[i][k] =  (arr[i][k-1] + arr[i][k+1] + arr[i+1][k]) / 3;
                }
            }
            else if(i == 19)
            {
                if(abs(arr[i][k] - arr[i][k-1]) > 1 && abs(arr[i][k] - arr[i][k+1]) > 1 && abs(arr[i][k] - arr[i-1][k]) > 1)
                {
                    arr[i][k] =  (arr[i][k-1] + arr[i][k+1] + arr[i+1][k]) / 3;
                }
            }
            else if(k == 0)
            {
                if(abs(arr[i][k] - arr[i-1][k]) > 1 && abs(arr[i][k] - arr[i+1][k]) > 1 && abs(arr[i][k] - arr[i][k+1]) > 1)
                {
                    arr[i][k] =  (arr[i-1][k] + arr[i+1][k] + arr[i][k+1]) / 3;
                }
            }
            else if(k == 29)
            {
                if(abs(arr[i][k] - arr[i-1][k]) > 1 && abs(arr[i][k] - arr[i+1][k]) > 1 && abs(arr[i][k] - arr[i][k-1]) > 1)
                {
                    arr[i][k] =  (arr[i-1][k] + arr[i+1][k] + arr[i][k-1]) / 3;
                }
            }
            else
            {
                if(abs(arr[i][k] - arr[i-1][k]) > 1 && abs(arr[i][k] - arr[i+1][k]) > 1 && abs(arr[i][k] - arr[i][k-1]) > 1 && abs(arr[i][k] - arr[i][k+1]) > 1)
                {
                    arr[i][k] =  (arr[i-1][k] + arr[i+1][k] + arr[i][k-1] + arr[i][k+1]) / 4;
                }
            }
        }
    }
}

int main(int argc, char **argv)
{
    FILE * fp1, *fp2;
    char str[SLEN];
    int num;
    int row = 20, line = 30;
    int arr1[row][line];
    char arr2[row][line+1];

    if(argc != 3)
    {
        fprintf(stderr, "Error, The parameter isn't right.\n");
        exit(EXIT_FAILURE);
    }
    if((fp1 = fopen(argv[1],"r")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[1]);
        exit(EXIT_FAILURE);
    }
    if((fp2 = fopen(argv[2],"w")) == NULL)
    {
        fprintf(stderr, "Can't open %s\n", argv[2]);
        exit(EXIT_FAILURE);
    }
    getIntData(row, line, arr1, fp1);
    dealData(row, line, arr1);
    tranData(row, line, arr1, arr2);
    showPicture(row, line, arr2);
    showInFile(row, line, arr2, fp2);
    if(fclose(fp1) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[1]);
    }
    if(fclose(fp2) != 0)
    {
        fprintf(stderr, "Can't close file %s\n", argv[2]);
    }
    return 0;
}

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-07-27 16:26:56  更:2021-07-27 16:28:55 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/20 13:27:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码