Skip to content

sku0x20/SemiColonAdder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SemiColonAdder

Appends Semicolon to C files.

Usage:-

./semiColonAdder readFileName writeFileName

Example:-

// cFile.c

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

int main(int argc, char* argv[]) {
    char const *const fileName = argv[1]
    FILE* file = fopen(fileName, "r") 
    char line[256]

    while (fgets(line, sizeof(line), file)) {
        /* note that fgets don't strip the terminating \n, checking its
           presence would allow to handle lines longer that sizeof(line) */
        printf("%s", line)
    }
    /* may check feof here to make a difference between eof and io failure -- network
       timeout for instance */

    printf("\n")

    fclose(file)

    return 0
}

Will get Converted to,

// cFile.c

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

int main(int argc, char* argv[]) {
    char const *const fileName = argv[1];
    FILE* file = fopen(fileName, "r");
    char line[256];

    while (fgets(line, sizeof(line), file)) {
        /* note that fgets don't strip the terminating \n, checking its
           presence would allow to handle lines longer that sizeof(line) */
        printf("%s", line);
    }
    /* may check feof here to make a difference between eof and io failure -- network
       timeout for instance */

    printf("\n");

    fclose(file);

    return 0;
}

Tests

3 test cases are tested which are included in tests folder.

./semiColonAdder ../tests/simpleSemicolonTest simpleSemicolonTest
./semiColonAdder ../tests/differentEnds.txt differentEnds.c
./semiColonAdder ../tests/cFile.c cFile.c

Exception

Function / Loop declared like

int main()
{
    // body
}

are not supported yet, ){ should be in same line.

int main(){
    // body
}

About

Appends Semicolon to C files

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages