Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free

Debug and Fix C Code

HardCoding00:00
Practice interviewer
In session
5 left
00:00

Whenever you're ready, walk me through how you'd approach this.

Sign up free to chat or submit. Log in

Problem

Teradata's batch loaders parse fixed-width customer transaction records out of a raw buffer before they're inserted into the warehouse. A junior engineer's first pass at this parser crashes intermittently on real production files.

#include <stdio.h>
#include <string.h>

void parse_record(char *buffer, char *out_customer_id, char *out_amount) {
    char customer_id[10];
    strcpy(customer_id, buffer);

    char *amount_field = buffer + 10;
    int amount = atoi(amount_field);

    strcpy(out_customer_id, customer_id);
    sprintf(out_amount, "%d", amount);
}

int process_batch(char **records, int count) {
    int total = 0;
    for (int i = 0; i <= count; i++) {
        char customer_id[10];
        char amount_str[20];
        parse_record(records[i], customer_id, amount_str);
        total += atoi(amount_str);
    }
    return total;
}

Identify all bugs in this C code and describe what problems each one causes. Explain what you'd change to make this safe to run against real production files, without necessarily rewriting every line.