Thread: writing backwards?

  1. #16
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Quote Originally Posted by Overworked_PhD View Post
    Ya know, anytime you want to meet me face to face for some kind of programming showdown, I'll be more than happy to show up and clown you like the rookie you are. Maybe we could get MK27 or tabstop to issue the programming problems. Then, in real life, without the aid of google or any other resource, we can go at it -).
    Can you explain this in complete detail?

    Code:
    #include <stdio.h> /*why not just use stdlib.h? */
    
    int
    main ()
    {
      printf ("Hello \n World!\n");
      return 1;
    }
    Ok I am done and I will not respond further to this. Makes for fun reading though. Perhaps !Overworked_PhD can post on xkcd?

  2. #17
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by slingerland3g View Post
    Can you explain this in complete detail?

    Code:
    #include <stdio.h> /*why not just use stdlib.h? */
    
    int
    main ()
    {
      printf ("Hello \n World!\n");
      return 1;
    }
    Ok I am done and I will not respond further to this. Makes for fun reading though. Perhaps !Overworked_PhD can post on xkcd?
    Technically it's undefined behavior. I can prove this by citing the bad line of code and the corresponding ANSI/ISO C passage.

  3. #18
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    Well the problem doesn't seem to specify whether to store the word backwards in an array so printing the original array in reverse would produce the same answer.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Overworked_PhD View Post
    Technically it's undefined behavior. I can prove this by citing the bad line of code and the corresponding ANSI/ISO C passage.
    As it's written, or making the change suggested by the comments?

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Overworked_PhD View Post
    Nah, I'm just proving that I can run circles around you when it comes to basic programing -).
    Well, I can reverse a string faster than you can!


    ( Holds mirror behind his back )


  6. #21
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by Adak View Post
    Well, I can reverse a string faster than you can!


    ( Holds mirror behind his back )

    Yo homegirl, I commented in my code that that it was a rookie way to reverse a string.

  7. #22
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by tabstop View Post
    As it's written, or making the change suggested by the comments?
    The original code, as it was presented, is technically undefined behavior. Now let's all wait for lasertard, I might laserlight to recite the corresponding passage.

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Overworked_PhD View Post
    The original code, as it was presented, is technically undefined behavior. Now let's all wait for lasertard, I might laserlight to recite the corresponding passage.
    Whether or not to wait for LL is up to you naturally, but I'll go out on a limb and say I don't believe you. For reference, the code I'm looking at is
    Code:
    #include <stdio.h> /*why not just use stdlib.h? */
    
    int
    main ()
    {
      printf ("Hello \n World!\n");
      return 1;
    }

  9. #24
    Registered User
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by Overworked_PhD View Post
    Wow, I'm slipping. Someone beat me to the response quicker than I could write the code -(. Anyways, maybe something like the following...

    Code:
    #include <stdio.h>
    
    #define MAXLINE 80
    
    /*Rookie way to reverse a string*/
    void reverse(char s[])
    {
      int i, j;
      char temp;
    
      i = 0;
      while (s[i] != '\0')
        ++i;
      --i;
      if (s[i] == '\n')
        --i;
      j = 0;
      while (j < i) {
        temp = s[j];
        s[j] = s[i];
        s[i] = temp;
        --i;
        ++j;
      }
    }
    
    int getline(char s[], int max)
    {
      int c, i;
      for (i = 0 ;i < max -1 && (c = getchar()) != EOF && c != '\n'; i++) 
        s[i] = c;
      if (c == '\n') {
        s[i++] = c;
      }
      s[i] = '\0';
      return i;
    }
    
    int main(void)
    {
      char line[MAXLINE];
    
      while (getline(line, MAXLINE) > 0) {
        reverse(line);
        printf("%s\n", line);
      }
    
      return 0;
    }
    [cd@localhost oakland]$ gcc -Wall -Wextra -Wshadow -ansi -pedantic easy.c -o easy
    [cd@localhost oakland]$ ./easy
    sex
    xes

    drugs
    sgurd

    chicks
    skcihc

    lalalalaliesoedosnomeosnffffffffffffffffffffffffff ffffffffffffffffffffffilolndodsmsoetssssssssssssss sssssssssssssssssssssssssssssssssssssssssiiiiiiii
    odnlolifffffffffffffffffffffffffffffffffffffffffff fffffnsoemonsodeoseilalalalal
    iiiiiiiissssssssssssssssssssssssssssssssssssssssss sssssssssssssteosmsd

    maybe
    ebyam

    [cd@localhost oakland]$
    thank you so much for help

  10. #25
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by tabstop View Post
    Whether or not to wait for LL is up to you naturally, but I'll go out on a limb and say I don't believe you. For reference, the code I'm looking at is
    Code:
    #include <stdio.h> /*why not just use stdlib.h? */
    
    int
    main ()
    {
      printf ("Hello \n World!\n");
      return 1;
    }
    This line

    Code:
    int
    main ()
    should either be

    Code:
    int
    main (void)
    or

    Code:
    int
    main (int argc, char **argv)

  11. #26
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's good to hear your seance worked out for you, so Stevens could help you with the above post. Dumbass.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #27
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by quzah View Post
    It's good to hear your seance worked out for you, so Stevens could help you with the above post. Dumbass.


    Quzah.
    This is coming from someone that has zero academic or professional credentials. Okay, maybe I'm wrong. How may Computer Science publications do you have to your name? Have may books have you co-authored?

  13. #28
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    MisterC is said to have authored books too, he even teaches! That doesn't make him any less of a dumbass. While you're at it, let me name drop Schildt. He's a dumbass too. Go look up the lists of terrible C/C++ books and you'll find his name all over the place. The guy that authored "C for Dummies"? Yep, his publications were incorrect in numerous places as well. Writing something doesn't automagically make you not a dumbass, as proof by all of your posts.


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #29
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Yes, the Schildt books suck. However, I know for a fact Schildt could still school you.

  15. #30
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    This line
    Code:
    int
    main ()
    should either be
    Code:
    int
    main (void)
    or
    Code:
    int
    main (int argc, char **argv)
    Yes, if you're using C++. But in C the (void) is assumed when you type "int main()" so it is not necessary.

    EDIT: Just realized that perhaps you were all on to that but still... I feel like I should point it out.
    Consider this post signed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems installing Mingw5.1.4
    By BlackOps in forum C Programming
    Replies: 2
    Last Post: 07-26-2009, 03:28 AM
  2. Replies: 2
    Last Post: 05-20-2008, 08:57 AM
  3. Very slow file writing of 'fwrite' function in C
    By scho in forum C Programming
    Replies: 6
    Last Post: 08-03-2006, 02:16 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM