Here's a detab utility.
This should bread and butter code. In fact it is tricky to ensure that a
malicious user cannot cause a buffer overrun. Hence the maxmemory() routine.
getline() is also difficult.
/*
Utility to replaces tabs in text files with spaces.
Can either do a blind replace or replace with user-specifed tab stops
By Malcolm McLean, 2009
- include <stdio.h>
- include <stdlib.h>
- include <string.h>
- include <limits.h>
- include <assert.h>
/*
count the occurences of ch in str
size_t chcount(const char *str, int ch)
{
size_t answer = 0;
while(*str)
if(*str++ == ch)
answer++;
return answer;
}
/*
is a string an integer?
int integral(char *str)
{
char *end;
long x;
if(!str)
return 0;
if(!*str)
return 0;
x = strtol(str, &end, 10);
if(x > INT_MAX || x < INT_MIN)
return 0;
if(*end)
return 0;
return 1;
}
/*
check that an array of integers is ascending...