• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[C/C++ Program] Create files

Newbie Spellweaver
Joined
Apr 19, 2014
Messages
16
Reaction score
1
Hello everyone,

It's very simple: I do a little program who create files in your directory. This files can have any extension (txt, cpp, php, css, whatever) but I don't include some function to check if your extension exist or not. It's like any operational system, right? If you create a file who this have a unknown extension, the system will not recognize the file. So is your responsibility create your file with a familiar extension.

The main objective of this software is provide a good features to the students of C/C++ language(s). Also because you look this and probably ask to yourself: "Oh my god, I never use this". Well, to the students, this is a privilege to turn a master in the features of ANSI. Yes, the program is 100% ANSI.

See the spoiller below:
First we enter the name of our file and the extension:

Raunchy - [C/C++ Program] Create files - RaGEZONE Forums


Raunchy - [C/C++ Program] Create files - RaGEZONE Forums


And so the file has been created.

Raunchy - [C/C++ Program] Create files - RaGEZONE Forums


THE RESULT:

Raunchy - [C/C++ Program] Create files - RaGEZONE Forums

Download:

Code:
//createfile.c : Console Application multi-plataform to create files.
//Developed by Zehou/Raunchy to Rage Zone.


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


#define MAXLOADSTRING   1000
#define MAXSIZE         100
#define CLEAR_B         fflush(stdin)
#define CLS             system("cls")


struct InfoFile {
    char namefile[MAXSIZE];
    char extensionfile[MAXSIZE];
    char stringfile[MAXLOADSTRING];
} f;


int createfile(char language1[])
{
    char local_escope;
    FILE *fpointer;
    int i;


    if (strcmp(language1, "portuguese") == 0)
    {
        fpointer = fopen(f.namefile, "w");


        if (fpointer != NULL)
        {
            do {
                CLEAR_B;
                printf("\nO arquivo %s foi criado com sucesso! Abra o seu diretorio e cheque-o.\n\n", f.namefile);
                printf("Para finalizar, voce deseja gravar uma mensagem em seu arquivo? (s/n) ");
                scanf("%c", &local_escope);
            } while (local_escope != 's' && local_escope != 'n');


            if (local_escope == 's')
            {
                printf("\nInsira aqui o que voce deseja que seja salvo: ");
                scanf("%s", &f.stringfile);


                for (i = 0; i <= strlen(f.stringfile); i++)
                    fputc(f.stringfile[i], fpointer);


                return 0;
            }


            else
            {
                fclose(fpointer);
                return 0;
            }
        }
    }


    else
    {
        fpointer = fopen(f.namefile, "w");


        if (fpointer != NULL)
        {
            do {
                CLEAR_B;
                printf("\nThe file %s has been created! Open your file location and check it.\n\n", f.namefile);
                printf("To finishing, do you want to load a message on your file? (y/n) ");
                scanf("%c", &local_escope);
            } while (local_escope != 'y' && local_escope != 'n');


            if (local_escope == 'y')
            {
                printf("\nEnter here what you want who stay saved in your file: ");
                scanf("%s", &f.stringfile);


                for (i = 0; i <= strlen(f.stringfile); i++)
                    fputc(f.stringfile[i], fpointer);


                return 0;
            }


            else
            {
                fclose(fpointer);
                return 0;
            }
        }
    }


    return 1;
}


void EnglishLanguage()
{
    char local_escope;
    char language[] = "english";


    CLS;
    CLEAR_B;
    printf("Enter the name of your file: ");
    scanf("%s", &f.namefile);


    printf("Enter the extension of your file: ");
    scanf("%s", f.extensionfile);


    while (strchr(f.extensionfile, '.') == NULL)
    {
        printf("\nWarning!\n");
        printf("Is necessary to introduce a extension for your file. Try again.\n\n");
        printf("Enter the extension of your file: ");
        scanf("%s", f.extensionfile);
    }


    strcat(f.namefile, f.extensionfile);


    do {
        CLS;
        CLEAR_B;
        printf("Full file name: %s\n", f.namefile);
        printf("Are you sure you want to confirm? (y/n) ");
        scanf("%c", &local_escope);
    } while (local_escope != 'y' && local_escope != 'n');


    if (local_escope == 'y')
    {
        CLEAR_B;
        createfile(language);
    }


    else
        return EnglishLanguage();
}


void PortugueseLanguage()
{
    char local_escope;
    char language[] = "portuguese";


    CLS;
    CLEAR_B;
    printf("Insira o nome do seu arquivo: ");
    scanf("%s", &f.namefile);


    printf("Insira a extensao do seu arquivo: ");
    scanf("%s", f.extensionfile);


    while (strchr(f.extensionfile, '.') == NULL)
    {
        printf("\nErro!\n");
        printf("Foi inserido nenhuma extensao para o arquivo. Tente novamente.\n\n");
        printf("Insira a extensao do seu arquivo: ");
        scanf("%s", f.extensionfile);
    }


    strcat(f.namefile, f.extensionfile);


    do {
        CLS;
        CLEAR_B;
        printf("Nome completo de seu arquivo: %s \n", f.namefile);
        printf("Deseja confirmar? (y/n) ");
        scanf("%c", &local_escope);
    } while (local_escope != 'y' && local_escope != 'n');


    if (local_escope == 'y')
    {
        CLEAR_B;
        createfile(language);
    }


    else
        return PortugueseLanguage();
}


int main(void)
{
    char local_escope;


    do
    {
        CLS;
        printf("Developed by Raunchy for Ragezone and Ragezone BR \n\n");
        printf("English or portuguese? (e/p) ");
        scanf("%c", &local_escope);
    } while (local_escope != 'e' && local_escope != 'p');


    if (local_escope == 'e')
        EnglishLanguage();


    else
        PortugueseLanguage();


    return 0;
}

OBS: If you use Linux or Macintosh, edit the defines to the right commands for your terminal/console.
*The main objective of this software is provide a good features to the students of C/C++ language(s).

Thank you.
 
very nice
Joined
Jul 5, 2013
Messages
518
Reaction score
80


iam getting this error iam begginer in C++ but i'll be Expert :D
 
Newbie Spellweaver
Joined
Apr 19, 2014
Messages
16
Reaction score
1


iam getting this error iam begginer in C++ but i'll be Expert :D

It happens because you are using the text editor of Miscrosoft, the Visual Studio. These editor returns a error message while its detect a command or function different of the default features of C/C++ from Windows. In this case, we use the ANSI features, so the editor returns a alert, but keep calm, this is only a message and don't have any influence on the software.

As the message said, to disable this problem its only necessary add _CRT_SECURE_NO_WARNINGS.
Search about it or contact me.
 
Back
Top