rollmorad hinzugefügt

This commit is contained in:
2015-11-15 23:18:06 +00:00
commit 948a6775ab
850 changed files with 117333 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
#include <iostream>
#include <cstdio>
int main(int argc, char** pp_args)
{
if(argc == 1)
{
std::cout << "Usage: addnewline file1 file2 file3 ..." << std::endl;
return 0;
}
else
{
int numErrors = 0;
for(int i = 1; i < argc; ++i)
{
FILE* p_file = fopen(pp_args[i], "rb");
if(!p_file)
{
std::cerr << "Couldn't open file " << pp_args[i] << std::endl;
++numErrors;
continue;
}
std::cout << pp_args[i] << ": ";
fseek(p_file, 0, SEEK_END);
long fileSize = ftell(p_file);
bool addNewLine = fileSize == 0;
if(fileSize)
{
fseek(p_file, fileSize - 1, SEEK_SET);
int ch = fgetc(p_file);
addNewLine = ch != '\n';
}
fclose(p_file);
if(addNewLine)
{
p_file = fopen(pp_args[i], "ab");
fputc('\n', p_file);
fclose(p_file);
std::cout << "added newline" << std::endl;
}
else
{
std::cout << "OK" << std::endl;
}
}
return numErrors;
}
}