Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 从文件中读取并指定为字符串,调用函数作为参数_C_Arrays_Function_File Io_Function Pointers - Fatal编程技术网

C 从文件中读取并指定为字符串,调用函数作为参数

C 从文件中读取并指定为字符串,调用函数作为参数,c,arrays,function,file-io,function-pointers,C,Arrays,Function,File Io,Function Pointers,我尝试使用传递函数作为参数,但我被卡住了。我有两个问题: 首先,我尝试在tfm中调用uppercase和open.txt。其次,我如何从in.txt中读取字符作为字符串并分配给char content[] #include <stdio.h> void tfm( char str_filename[], void(*pf_convertion)( char content[])); void uppercase(char content[]); //converts all

我尝试使用传递函数作为参数,但我被卡住了。我有两个问题: 首先,我尝试在tfm中调用uppercase和open.txt。其次,我如何从in.txt中读取字符作为字符串并分配给char content[]

#include <stdio.h>
void tfm( char str_filename[], void(*pf_convertion)( char content[]));
void uppercase(char content[]);     //converts all letters to uppercase
int main(){

    puts("-------------------------------");
    printf("tfm:\n");
    tfm("in.txt", uppercase);
    puts("-------------------------------");

    return 0;
}

void tfm( char str_filename[], void(*pf_convertion)( char content[])){

    FILE *fptr_in;

    if((fptr_in=fopen(content,"r"))==NULL){
        printf("Error reading file\n");
    }
    else{
        (*pf_convertion)(str_filename);
    }
}

void uppercase(char content[]){

    char ch;
    int st;

    for(st=fscanf(fptr_in,"%c",&ch);
        st==1;
        st=fscanf(fptr_in,"%c",&ch)){

            if('a'<=ch && ch<='z'){
                ch-=32;
                printf("%c",ch);
            }
            else
                printf("%c",ch);
        }

    }
#包括
void tfm(字符str_文件名[],void(*pf_转换)(字符内容[]);
无效大写字母(字符内容[])//将所有字母转换为大写
int main(){
认沽权(“------------------------------------”;
printf(“tfm:\n”);
tfm(“in.txt”,大写);
认沽权(“------------------------------------”;
返回0;
}
void tfm(字符str_文件名[],void(*pf_转换)(字符内容[]){
文件*fptr_in;
if((fptr_in=fopen(content,“r”))==NULL){
printf(“读取文件时出错”);
}
否则{
(*pf_转换)(str_文件名);
}
}
无效大写(字符内容[]){
char ch;
int st;
对于(st=fscanf(fptr_in,“%c”和ch);
st==1;
st=fscanf(fptr_in、%c、&ch)){

如果('a'注:在调用
main()
之前,应该先原型化或声明
tfm()
。首先,这个词是“分配”,而不是“分配”。其次,这里的第一条规则是“每篇文章一个问题”。这个网站设计成问答(Q&a)网站,而不是问答(Qs&As)网站。如果你有两个问题,发两篇帖子。你可以从第二个帖子链接到第一个帖子。谢谢@KenWhite我会注意的。你误解了每个功能的作用。