I have to take a name typed by the user and create a file with this name... LING. C

Asked

Viewed 60 times

-1

#include <stdio.h>

int main (){

    char nome_arq[20];
    printf("Digite o nome do arquivo: ");
    scanf("%s",&nome_arq);
    FILE *file;
    file=fopen("-------.txt","w");
    fprintf(file,"huahuahuahuauh");
    fclose(file);

return 0;
}

1 answer

2


Having the #include <string.h> you can use the strcat(str1, str2) function to concatenate 'strings', leaving your logic more or less like this:

file=fopen(strcat(nome_arq, ".txt"),"w");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.