Talk:If(j)invert()if(l)change()if(q)input()if(t)output(x);

From Esolang
Jump to navigation Jump to search

This need some additions.--(this comment by Lucasieks at 2014-05-02T19:07:20 UTC; please sign your comments with ~~~~)

Tried better implementation in C99

Here is the code:

/*
 * miajlqt.c
 *
 * coded in C99, I think
 *
 * coded in 2020-01-26, around 00:10 (JST/UTC+8)
 *
 * coded by User:YamTokTpaFa
 * <https://esolangs.org/wiki/User:YamTokTpaFa>
 *
 * This is an implementation of an interpreter
 * for an esoteric programming language
 * 'If(j)invert()if(l)change()if(q)input()if(t)output(x)
;'
 *
 * The information of the language can be found below:
 * <https://esolangs.org/wiki/If(j)invert()if(l)change()
if(q)input()if(t)output(x);>
 *
 * I, YamTok, would like to publish this code under
 * public domain, but how am I supposed to do so?
 *
 * USAGE
 *      this-program your-program-file
 */
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char** argv){
        // Usage printer
        if(argc!=2){
                fprintf(stderr,
                        "usage: %s file\n",
                        argv[0]);
                exit(EXIT_SUCCESS);
        }
        // File opener
        FILE*fp;
        fp=fopen(argv[1],"r");
        if(fp==NULL){
                fprintf(stderr,
                        "%s: could not open %s\n",
                        argv[0], argv[1]);
                exit(EXIT_FAILURE);
        }
        // Program executer below //
        // // Initial configurator
        int mem[]={0,0};
        int ptr=0;
        // // Executer
        int c=fgetc(fp);
        while(c!=EOF){
                if(c=='j')
                        mem[ptr]=!mem[ptr];
                else if(c=='l')
                        ptr=!ptr;
                else if(c=='q')
                        scanf("%d",&mem[ptr]);
                else if(c=='t')
                        putchar(mem[ptr]);
                else
                        putchar(c);
                c=fgetc(fp);
        }
        // Final processor
        fclose(fp);
        exit(EXIT_SUCCESS);
}

I tested with three Hello World programs. Is this what you expected? --YamTokTpaFa (talk) 15:19, 25 January 2020 (UTC)

Cat

Should qlt be a cat?