LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > MrCode
User Name
Password

Notices


This is the first "blog" of any kind I've ever had, so it's probably not the greatest...

Just a little snippet about me:

I'd like to consider myself relatively tech-savvy; obviously I use Linux (Arch to be precise; K.I.S.S. FTW), and I enjoy learning new things about computers in general (both software and hardware-related).

This blog is mostly just for whenever I feel like telling the world about my experiences with computers/Linux (or just life in general), or just posting for the hell of it.
Rate this Entry

no

Posted 03-14-2011 at 10:52 PM by MrCode
Updated 04-02-2011 at 03:28 PM by MrCode (Major program revision)

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

int main(int argc,char** argv)
{
    char* str = malloc(1);
	
    if(argc >= 2)
    {
        int i;
        for(i = 1; i < argc; i++)
        {
            strcat(str," ");
            strcat(str,argv[i]);
        }
        
        int len = strlen(str);
     
        while(1)
        {
            while(len--)
                putchar(str[len]);

            putchar('\n');
			
            len = strlen(str);
        }
    }
    else
    {
        while(1)
            printf("n\n");
    }

    return 0;
}
This is my silly little nod to the "yes" program. The only thing it does differently is that it prints the string reversed.

Code:
[mrcode@lappy486 ~]$ no The quick brown fox jumps over the lazy dog.
hT
.god yzal eht revo spmuj xof nworb kciuq ehT
.god yzal eht revo spmuj xof nworb kciuq ehT
.god yzal eht revo spmuj xof nworb kciuq ehT
.god yzal eht revo spmuj xof nworb kciuq ehT
.god yzal eht revo spmuj xof nworb kciuq ehT
.god yzal eht revo spmuj xof nworb kciuq ehT
...
Compiled with:

Code:
gcc -Wall -Werror -pedantic -std=c99 -o no no.c
...flawlessly. It's even in my /usr/bin.

EDIT: Argh, I was right about one thing: it definitely terminates on SIGSEGV (segfaults when run without params).

EDIT of EDIT: The program has been revised...the first if clause was redundant, and the goto has been removed. Output has also been edited (turns out it ain't perfect ).
Views 1616 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration