Originally I have a .txt file where I have the bibliography of some sources in bibtex format, and I want to extract the data and order it in apa style.

Dani AI

Generated

A practical plan for a C program to turn a BibTeX .txt into APA-style references, building on the thread: has BibTeX entries and needs APA output; noted converters exist (useful for reference), and raised parser-generator and academic-plagiarism points — both worth keeping in mind.

Start by designing a small parser: read the file, strip comments, then split into BibTeX entries (recognize the leading @type{key, ...}). Parse fields robustly by handling both quoted and brace-delimited values and nested braces. Do not rely on simple regular expressions for nested braces; implement a small state machine or recursive extractor so you correctly capture titles with braces and LaTeX escapes.

Map BibTeX fields to APA components: authors, year, title, container (journal/book), volume(issue), pages, publisher, DOI/URL. Normalize author names: split on " and ", detect "Last, First" vs "First Last", and format as "Last, F. M." Apply APA ordering rules (alphabetical by author, then year) and disambiguate same-author same-year entries with "a", "b", etc. Confirm which APA edition your course requires because author-list and formatting rules changed (for example, the 7th edition has different author-list limits).

C-specific tips: prefer dynamic buffers and check malloc results, free memory, and unit-test parsing on many edge cases (corporate authors, missing year, multiple editors, accented/TeX macros). If the assignment allows, a lexer/parser generator will reduce low-level parsing code; if not, implement careful token handling and small helper functions for name and DOI formatting. Keep tests and documentation so the grader can follow design choices.

Recommended Answers

All 4 Replies

Thank you for the help but I need to male a Progra in C

I can't find such in C so you have quite the project in front of you.

If you need source code so you can command line this I suggest https://github.com/backtracking/bibtex2html

I'm going to skip the command line use here but yes it does what you asked, has source code and despite the "html" in the name, it has the -nodoc switch that supresses the opening and closing html code necessary to make a stand-alone document.

Are there any other contraints on the assignment (which I am presuming is for a compiler course, since it is basically a parsing problem)? Are you allowed to use a lexical analyzer generator (e.g., flex) and/or a parser generator (e.g., bison)? Are there any requirements for the method used?

Note that professors can use Google to find students' posts, and often do. Just something to keep in mind.

commented: That makes me recall the Trinity of Flex, Bison and YACC. Yup, you can make source code with that! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.