Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

ITT the ABC Programming Language

Name: Anonymous 2008-07-29 19:29

#include <stdio.h>

int main(int argc,char argv*[]){
  int i = 0;
  int BUFFA;

  while(argv[i]!='\0'){
    if(argv[i]='a')
      BUFFA++;
    else if(argv[i]='b')
      BUFFA--;
    else if(argv[i]='c')
      printf("%i\n",BUFFA);
    else printf("%s","Error.\n");
  }
}

Name: Anonymous 2008-10-27 16:09

ITT: /prog/ releases open source software.


/* abc.c: an ABC interpreter. Released into the public domain. */

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

int main(int argc, char* argv[])
{
    printf("ABC interpreter v0.0.1a by /prog/\n\n");
    if(argc < 2)
    {
        fprintf(stderr, "Error: no program text.\n\nUsage: %s [program text]\n", argv[0]);
        return 1;
    }
    else if(argc > 2)
    {
        fprintf(stderr, "Warning: more than 1 argument detected, ignoring trailing arguments.\n");
    }

    int acc = 0;
    int l = strlen(argv[1]);
    int i;
    for(i = 0; i < l; i++)
    {
        if    (argv[1][i] == 'a') { acc++; }
        else if    (argv[1][i] == 'b') { acc--; }
        else if (argv[1][i] == 'c') { printf("%d\n", acc); }
        else
        {
            printf("Error:c%d:unrecognised character.\n", i);

            /* print line that error was on, and underneath put a ^ to indicate what char we can't parse */
            char* progstr = malloc(i * sizeof(char) + 1);
            int j;
            for(j = 0; j <= i; j++)               
            {
                progstr[j] = argv[1][j];
            }
            progstr[i + 1] = '\0';

            char arrowstr[i + 1];
            int k;
            for(k = 0; k < i; k++)
            {
                arrowstr[k] = ' ';
            }
            arrowstr[i] = '^'; arrowstr[i + 1] = '\0';

            printf("%s\n", progstr); /* this (rather than just printf(progstr);) is to stop users from putting placeholders in the program string, causing printf() to parse them */
            printf("%s\n", arrowstr);

            return 1;
        }
    }

    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List