Generate New C File
eharetea

A program that generates a blank C file with the specified filename, then opens the file in a vi editor in the terminal.

Create a new C file and add it to your library.

Date Created:Tuesday February 27th, 2007 09:44 PM
Date Modified:Saturday August 02nd, 2008 01:47 PM


/*
*
* Generates a new .c file with main function
* Author: Dan Lynch
*
*/

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


int main()
{
        char filename[1024];
        FILE *dan;

        printf("Enter a Filename:\n");
        scanf("%s", &filename);

        strncat(filename".c", (strlen(filename)+2) );

        dan fopen filename"w" );
        if ( dan == NULL printf("Cannot open file!");
        fprintf(dan,"#include <stdio.h>\n\nint main()\n{\n\n\n\n\treturn 0;\n}\n");
        fclosedan );

        return 0;
}




/*
*
* Generates a new .c file with main function
* Opens file in vi editor
* Author: Dan Lynch
*
*/

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


int main()
{
        char filename[1024];
    char vifile[1024]="vi ";        
    FILE *dan;

        printf("Enter a Filename:\n");
        scanf("%s", &filename);

        strncat(filename".c", (strlen(filename)+2) );

        dan fopen filename"w" );
        if ( dan == NULL printf("Cannot open file!");
        fprintf(dan,"#include <stdio.h>\n\nint main()\n{\n\n\n\n\treturn 0;\n}\n");
        fclosedan );
    
    strncat(vifilefilenamestrlen(filename)+strlen(vifile) );

    system(vifile);    

        return 0;
}





Downloads:
Download: gen.c 559 B
Download: newfile.c 703 B

Please login or Click Here to register for downloads
Creative Commons License
Generate New C File by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com