Skip to content

Instantly share code, notes, and snippets.

@neilisaac
Created April 14, 2013 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilisaac/5380691 to your computer and use it in GitHub Desktop.
Save neilisaac/5380691 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LINESIZE 256
int main(int argc, char **argv){
printf("\\documentclass{article}\n\n");
char author[64];
char title[64];
fgets(author, 64, stdin);
fgets(title, 64, stdin);
*strchr(author, '\n') = '\0';
*strchr(title, '\n') = '\0';
printf("\\author{%s}\n\\title{%s}\n\\date{}\n\n", author, title);
printf("\\usepackage{dropping}\n\n");
printf("\\begin{document}\n\\maketitle\n");
char *line = calloc(LINESIZE, sizeof(char));
while(fgets(line, LINESIZE, stdin)){
if(!*line || *line == '\n')
continue;
else if(isdigit(*line)){
int n;
sscanf(line, "%d", &n);
printf("\\section*{Chapter %d}\n", n);
}
else if(*line && isspace(*line))
printf("\n%s", line);
else
printf("%s", line);
}
printf("\\end{document}\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment