Home > Programming > Reflecting while studying C language

Reflecting while studying C language

Run the following C program

#include <stdio.h>
#include <string.h>
int main (int argc, char const *argv[]){
        if(!argv[1]) return 0;
        int i = strlen(argv[1]);
        while(i > -1){
                printf("%c",argv[1][i]);
                i–;
        }
        printf("\n");
}
 

Using this string as first program parameter:

"..eromyna ti ekat t'nac I ?nwod edispu semit ynam os dlrow eht si yhW"

Related posts

Categories: Programming Tags: , ,
  1. Manuel
    February 21st, 2008 at 02:51 | #1

    Hey.. I tried to run the program with the parameter “LOL”, but it doesn’t seem to work to me… =)

    *LOL*

  2. February 21st, 2008 at 11:47 | #2

    Hhhhmmm have you tried turning your pc off and on again? ;)

    * ROFL *

  3. February 21st, 2008 at 15:14 | #3

    Loool!! and now with pointers ;-)

    #include
    #include

    int main (int argc, char** argv)
    {
    if (argc != 2)
    return 0;

    char* c = argv[1] + strlen(argv[1]);

    while (c– != argv[1])
    printf(“%c”, *c);

    printf(“\n”);
    }

  4. February 21st, 2008 at 15:16 | #4

    “c–” should be “c minus minus”.. damn autoformatting!

  5. Ami
    February 22nd, 2008 at 00:36 | #5

    “Why is the world so upside down? I can’t take it anymore..”

  6. February 22nd, 2008 at 14:16 | #6

    @ami
    suineg a era uoy,aitnama

    @benjamin
    Pointers are so cool! I just wrote this code today morning, without looking at your ;) Yes, you were right

    #include <stdio.h>
    #include <string.h>
    int main (int argc, char *argv[]){
    if(!argv[1]) return 0;
    char *p = argv[1] + strlen(argv[1]);
    while(p--!=argv[1]){
    printf("%c",*p);
    };
    printf("\n");
    }

  7. February 22nd, 2008 at 20:22 | #7


    #include <stdio.h>

    main (int argc, char const *argv[]){
    char *p;
    p = &argv[1][0];
    int a = strlen(argv[1]);
    while (a >= 0){
    printf("%c", *(p+a));
    a--;
    }
    printf("\n");
    }

    Less geek, but still working :)

  1. No trackbacks yet.