Skip to content

Instantly share code, notes, and snippets.

@mp607
Created November 6, 2013 13:53
Show Gist options
  • Save mp607/7336389 to your computer and use it in GitHub Desktop.
Save mp607/7336389 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
/* Real file path */
char *filepath = argc[argv-1];
/* check .txt file */
char *type = &filepath[strlen(filepath) -4];
if (strcmp(type, ".txt") != 0)
{
printf("No .txt file get. Exit!\n\nUsage: Drag any .txt file to it.\n");
#ifdef __WINDOWS_
system("pause");
#endif
return 0;
}
/* new file path */
char newpath[10000];
strcpy(newpath, filepath);
newpath[strlen(newpath)-4] = '\0';
strcat(newpath, "enter.txt");
FILE *fp = fopen(filepath, "r");
FILE *new = fopen(newpath, "w");
char s[100];
int i=0;
while (fgets(s, 99, fp) != NULL )
{
if (*s != '\n')
{
fprintf(new, "%s\n", s);
}
else
{
i++;
if (i > 1) fprintf(new, "\n");
}
}
fclose(fp);
fclose(new);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment