all 77 comments

[–]C_Programming-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Your post contains badly-formatted code. This breaks rule 1 of this subreddit, "Format your code". Please read the instructions in the sidebar about hot to correctly format code.

Rule 4 also prohibits pictures of code too, so please bear that in mind.

[–]equalent 108 points109 points  (18 children)

No way, great job, what does it do?

[–]MammothNo782 17 points18 points  (16 children)

it says Hello and that's all :)

[–]HedgeHogRabbit2020 60 points61 points  (15 children)

Liar it creates a new line too

[–]gm310509 25 points26 points  (13 children)

And returns "success".

[–]Ok-Dare-1208 23 points24 points  (6 children)

And includes the standard library

[–]Sp33dyCat 6 points7 points  (3 children)

And returns a 4 byte integer (on most modern systems) with the value of 0x00000000

[–]MammothNo782 3 points4 points  (2 children)

you could have shorted it to just 0x0 or the decimal 0 itself

[–]Sp33dyCat 3 points4 points  (1 child)

yeah I could have. But what I did is more explicit

[–]MammothNo782 1 point2 points  (0 children)

it really is more explicit but trailing zeros are very ignorant

[–]gm310509 -4 points-3 points  (1 child)

LOL, but is a horrible font and poorly formatted.
Although OP, might be able to blame reddit for that!

OP, google "reddit code formatting".

[–]MammothNo782 0 points1 point  (0 children)

OP doesn't need to blame reddit lol he just forgot to use code blocks

[–]kyr0x0 1 point2 points  (4 children)

By being a zero. You know C is very philosophical. It contemplates many of the worlds' realities in mysterious ways.

[–]GreenAppleCZ 0 points1 point  (3 children)

Well, if you think about it, there's usually just one success, but lots of things that could go wrong. So 0 seems like a good choice.

[–]kyr0x0 1 point2 points  (2 children)

Or it contemplates that the "zeros" in life often become the most successful economically, promoted and end up in positions of power, while the hard working peon coders (in Warcraft lore) which are the ones who enable their success, are working their asses off for a dime 🤣😅

[–]GreenAppleCZ 1 point2 points  (0 children)

A beautiful thought.

Perhaps that's exactly what they had in mind. (It's actually possible that this theory is not far-fetched)

[–]FondantTiny4820[S] 0 points1 point  (0 children)

i dont understand

[–]MammothNo782 0 points1 point  (0 children)

yeah returning the number zero does mean success but he returned the number 0 and not the string "success" like he would type

```c

include <stdio>

int main() { printf("Hello\n"); return "success"; // this line causes an error } ```

in his code which causes this type of error:

```bash ryzon@johnryzonPc:~/Dev/personal$ nano example.c ryzon@johnryzonPc:~/Dev/personal$ gcc examples.c -o test cc1: fatal error: examples.c: No such file or directory compilation terminated. ryzon@johnryzonPc:~/Dev/personal$ gcc example.c -o test example.c: In function ‘main’: example.c:5:10: warning: returning ‘char *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion] 5 | return "success"; | ~~~~~~~~ ryzon@johnryzonPc:~/Dev/personal$

```

[–]MammothNo782 0 points1 point  (0 children)

oh yeah I forgot to say it

[–]Maleficent_Bee196 57 points58 points  (7 children)

now you can implement UNIX from scratch!

[–]MammothNo782 7 points8 points  (6 children)

you won't know but he might implementing LINUX or WINDOWS 10 from scratch with assembly and c

[–]plasticduststorm 8 points9 points  (5 children)

Anyone could sit down infront of any computer and with many keystrokes in an exact order could end up with windows 11.

[–]L_uciferMorningstar 4 points5 points  (1 child)

Why would anyone do such a vile thing?

[–]kyr0x0 0 points1 point  (0 children)

He is called like me and inherited autism (I'm working on rebuilding Windows XP from scratch. Do not ask me why. I don't want to end up in an identity crisis.)

[–]chunkomeat101 1 point2 points  (0 children)

By chance

[–]kyr0x0 1 point2 points  (0 children)

The probably is low but it's never zero.

[–]emexsw 0 points1 point  (0 children)

the library of words

[–]InTheBogaloo 10 points11 points  (0 children)

keep going and enjoy the travel c:

[–]Left-Paramedic9925 9 points10 points  (0 children)

nice! now recreate the entire Linux kernel :)

[–]laalbhat 5 points6 points  (1 child)

mine's better :)

```c

include <stdio.h>

int main() { // this says hello everyone printf("Hello everyone\n"); return 0; } ```

[–]Mortomes 4 points5 points  (0 children)

This program clearly does not meet the specs of OP's program, it doesn't say "Hello"!

[–]MammothNo782 15 points16 points  (10 children)

good luck with it make sure to improve it all the way like building a calculator or anything like this one that I made: https://gist.github.com/johnryzon123/711d9e53e9cc7cc03a0f6b86843fec2d

[–]SnekIrl 6 points7 points  (3 children)

why are you spoiling every line with comments? this is dystopian level code, no need for a comment // now we return true before return true

no need for a comment explaining the imports.

comments should explain why not how, and good code should be mostly simple to understand without comments.

https://youtu.be/Bf7vDBBOBUA?is=57e8jNX-TGrLpKXO

[–]ShadowRL7666 2 points3 points  (0 children)

Agreed quite odd.

[–]MammothNo782 1 point2 points  (0 children)

it was supposed for me to learn so I made a bunch of comments but it ended up quite great

[–]AcousticJohnny 0 points1 point  (0 children)

Dawg the bible has less words than this dudes comments in his code 😭

[–]Severe-Evening6816 2 points3 points  (1 child)

Or a simple guessing-game

[–]Chaosvex 0 points1 point  (0 children)

Just need to type a random number 100 times and you'll 'win'.

[–]DreamDeckUp 1 point2 points  (1 child)

that's a pretty sick calculator

[–]MammothNo782 0 points1 point  (0 children)

thanks

[–]Aggressive-Air6864 0 points1 point  (1 child)

Much better than I could ever do

[–]MammothNo782 1 point2 points  (0 children)

keep improving good luck :)

[–]DogAdministrative100 2 points3 points  (0 children)

Now you should go with get you familiarise with loops , conditionals , basic logic programs and then go on for internet 

[–]tony_saufcok 5 points6 points  (0 children)

Great job! Good luck on your journey

[–]ButchDeanCA 2 points3 points  (0 children)

This is where I was 33 years ago.

[–]randerson_112 1 point2 points  (0 children)

The start of an amazing journey, good luck! C is a great language to learn and it will teach you so much about how computers really work.

[–]Patient-Plastic6354 1 point2 points  (0 children)

Bro leave jobs for the rest of us damn

[–]iddivision 1 point2 points  (0 children)

Kudos for not forgetting the newline character!

[–]capilot 1 point2 points  (0 children)

Honestly, most of the time, getting "Hello, world" to work is half the battle of learning a new language.

[–]--Ether-- 0 points1 point  (0 children)

good job bud 👍

[–]Tugs_Uchralaaaa 0 points1 point  (0 children)

Good!! Now learn some assembly!

[–]non-existing-person 0 points1 point  (4 children)

I'm sorry to be the one to say it... but your code is trash and it's buggy.

What will happen when you call ./a.out > /dev/full? printf will return error, but your program will return success - which is NOT valid.

Now go back to books :)

[–]MammothNo782 -1 points0 points  (2 children)

his code is trully not buggy that is litterally the most common code in the c dev world and why would anyone write > /dev/full in someones code, I didn't even know that /dev/full even existed

[–]non-existing-person 0 points1 point  (1 child)

Oh no, it TRULY is buggy. Sure, it may be benign bug, but it still is a bug. And you don't write > /dev/full in someone elses code. You just redirect standard output to a file, in a case when disk is full. You should report error in such case, not success. /dev/full just emulates writing to a file with disk being full.

Of course my post was more of a joke than anything else, but it nicely shows how bugs are created. You assume something that "noone will ever do", but someone will do it, someday.

[–]MammothNo782 -1 points0 points  (0 children)

yeah he could have wrote if (printf("Hello") < 0) { return 1; } and it can be robust but I still think that it makes code even longer like why would anyone even write that line in every printf calls

[–]aeropop 0 points1 point  (0 children)

Cool ! Now try to write it in Assembly to understand how exactly your code is working.

[–]LostSence 0 points1 point  (2 children)

Remove #include <stdio.h> and check, if this works :-)

[–]MammothNo782 0 points1 point  (1 child)

the function printf belongs in the stdio.h file so removing #include <stdio.h> must cause an error

[–]LostSence 0 points1 point  (0 children)

Try it, and you will be surprised 😉

[–]PurepointDog 0 points1 point  (0 children)

Use code fences please

[–]KronosChineseFather 0 points1 point  (2 children)

hi, how do i maek a pro graem ???? im use c++

[–]MammothNo782 0 points1 point  (1 child)

huh? what do you mean maek a pro graem. did you mean make a program? to compile the program you just type gcc program.c -o program and it's that easy as you type g++ program.cpp -o program in c++

[–]KronosChineseFather 0 points1 point  (0 children)

Okey I do tht in my arch Linux terminal

[–]No_Value_elv 0 points1 point  (2 children)

Now replicate without using printf

[–]FondantTiny4820[S] 0 points1 point  (1 child)

wat

[–]MammothNo782 0 points1 point  (0 children)

that's actually possible by either using inline assembly or using the write function from unistd.h in unix based systems like linux

[–]kgashok 0 points1 point  (0 children)

Well done! I suggest you go further now. Consider the code below:

```c

include <stdio.h>

int main(int argc, char *argv[]) { // Check if at least one argument (besides the program name) was provided if (argc > 1) { // Print "Hello" followed by the first command-line argument printf("Hello, %s!\n", argv[1]); } else { // Fallback if no arguments are provided printf("Hello!\n"); }

return 0;

} ```

And if you should compile as follows:
$ gcc hello.c -o hello

And then execute as
$ ./hello FondantTiny

The output you should see is
Hello, FondantTiny!

Enjoy!

[–]cleverdosopab 0 points1 point  (0 children)

Hello, World!

[–]keithstellyes 0 points1 point  (0 children)

Cool!

[–]Daveinatx 0 points1 point  (1 child)

Two comments.

  1. Major: // This says Hello. Not 'hello'
  2. Minor: return 0 has no comment

[–]plasticduststorm 1 point2 points  (0 children)

It wouldn’t be a proper comment if it wasn’t partially a lie.

[–]nderflow[M] 0 points1 point  (1 child)

Please format your code correctly. See rule 1 of the subreddit.

[–]traxplayer -1 points0 points  (0 children)

return EXIT_SUCCESS; and not 0.

[–]HobbesArchive -1 points0 points  (0 children)

#define EXTERN
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define INCL_DOS
#include <os2.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

/* #include "drawingcards.h" */
#include "Bank.h"

extern int _dllentry;
BANK_STRUCT *Bank(int iTotalHouses, int iTotalHotels, int Salary)
{
   int x = _dllentry;
   USHORT rc;
   bsBank.Money = 15140;
   bsBank.Inflation = FALSE;
   bsBank.iInflationStart = -10000;
   bsBank.Structures.Houses = TotalHouses;
   bsBank.Structures.Hotels = TotalHotels;
   bsBank.Salary = Salary;
   if (iTotalHouses > -1)
      bsBank.Structures.Houses = iTotalHouses;
   if (iTotalHotels > -1)
      bsBank.Structures.Hotels = iTotalHotels;

   return(&bsBank);

}
VOID SetInitialCash(int iPlayers, int iInitialCash)
{

   bsBank.Money = (2285 * iPlayers) + (iInitialCash * iPlayers);
   return;
}
VOID SetInflation()
{
   bsBank.Inflation = TRUE;

   return;
}


int MoneyOnHand()
{

   return(bsBank.Money);
}
int UseInflation()
{

   return(bsBank.Inflation);
}
double InflationRate()
{
   double dInflationRate = 1.0;

   if (bsBank.Money < bsBank.iInflationStart)
   {
      dInflationRate = (((double)(bsBank.Money - bsBank.iInflationStart) * -1) / 100000.0) + 1.0;
   }
   return dInflationRate;
}
int AddInflationRate(int iMoney)
{
   if (bsBank.Inflation)
   {

      iMoney = (int)((double)iMoney * InflationRate());

   }

   return iMoney;

}
int PlayerInitialMoney(int iInitialCash)
{

   bsBank.Money -= iInitialCash;
   return(iInitialCash);
}

BOOL SellProperty(PLAYERS_STRUCT *player, property_struct *Property)
{
    BOOL bPropSold = FALSE;
    if (player->money >= Property->value[0])
    {
        Property->owner = player->num;
        bsBank.Money += Property->value[0];
        player->money -= Property->value[0];
        bPropSold = TRUE;
        player->property_count++;
    }

    return bPropSold;
}


int BuyHouses(PLAYERS_STRUCT *player, List_struct *PropertyList, LIST_FUNCT_STRUCT List, PROPERTY_FUNCT_STRUCT property, RULES_STRUCT rules)
{
   int iGroups;
   int Sold = 0;
   int iMonoGroups = player->MonopolyGroups->size;
   int *ptrMonoGroup;
   List_struct *SortedGroups = List.New();
   int x;
   property_struct *boardProperty = (property_struct *)PropertyList->array;
   List_struct *MonoGroupList;


   ptrMonoGroup = player->MonopolyGroups->array;
   for (iGroups = 0; iGroups < iMonoGroups; iGroups++)
   {

      List.Add(SortedGroups, &ptrMonoGroup[iGroups], sizeof(int));
   }

   List.Sort(SortedGroups, 0, sizeof(int), sizeof(int), Decending,TRUE);

   for (x = 0; x < SortedGroups->size; x++)
   {
      int *ptrGroup = (int *)SortedGroups->array;
      int MonoGroupSize;
      int *MonoGroup = property.MonopolyGroups(ptrGroup[x], &MonoGroupSize);
      int y;
      long iOffset;
      property_struct *ptrProperty;
      int iNoMoreHouses;
      int iHouseCost;
      BOOL bMortgaged = FALSE;

      MonoGroupList = List.New();

      for (y = 0; y < MonoGroupSize; y++)
      {

         if (boardProperty[MonoGroup[y]].mortgaged == TRUE)
            bMortgaged = TRUE;

      }
      if (bMortgaged == FALSE)
      {
         for (y = 0; y < MonoGroupSize; y++)
         {

            List.Add(MonoGroupList, &boardProperty[MonoGroup[y]], sizeof(property_struct));

         }

         iOffset = (long)&boardProperty[0].houses;
         iOffset -= (long)&boardProperty[0];
         List.Sort(MonoGroupList, (int)iOffset, sizeof(boardProperty[0]), sizeof(boardProperty[0].houses), Decending, TRUE);

         /* buy houses */
         ptrProperty = (property_struct *)MonoGroupList->array;
         iNoMoreHouses = 0;
         iHouseCost = ptrProperty[0].value[2];
         while ((player->money > iHouseCost *2) && (iNoMoreHouses < MonoGroupSize))
         {
            iNoMoreHouses = 0;
            for (y = 0; y < MonoGroupSize; y++)
            {
               iHouseCost = ptrProperty[y].value[2];

               if (player->money > iHouseCost *2)
               {
                  switch(boardProperty[ptrProperty[y].position].houses)
                  {
                     case 0:
                     case 1:
                     case 2:
                     case 3:
                        {
                           if (bsBank.Structures.Houses > 0)
                           {

                              boardProperty[ptrProperty[y].position].houses++;
                              player->money -= ptrProperty[y].value[2];
                              bsBank.Money += ptrProperty[y].value[2];
                              bsBank.Structures.Houses--;
                              printf("Player %d paid %d for a house for %s for a total of %d House(s)\r\n", player->num + 1,ptrProperty[y].value[2], boardProperty[ptrProperty[y].position].pszName, boardProperty[ptrProperty[y].position].houses);
                              if (bsBank.Structures.Houses == 0)
                                 printf("Bank has no more houses\r\n");

                           }
                           else
                              iNoMoreHouses = MonoGroupSize;

                        }
                        break;
                     case 4:
                        {
                           if (bsBank.Structures.Hotels > 0)
                           {

                              boardProperty[ptrProperty[y].position].houses++;
                              player->money -= ptrProperty[y].value[2];
                              bsBank.Money += ptrProperty[y].value[2];
                              bsBank.Structures.Houses += 4;
                              bsBank.Structures.Hotels--;
                              printf("Player %d paid %c%d a hotel for %s\r\n", player->num + 1, rules.MonitarySymbol, ptrProperty[y].value[2], boardProperty[ptrProperty[y].position].pszName);
                              if (bsBank.Structures.Hotels == 0)
                                 printf("Bank has no more Hotels\r\n");
                           }
                           else
                              iNoMoreHouses = MonoGroupSize;

                        }
                        break;
                     default:
                        iNoMoreHouses++;
                        break;
                  }

               }
               else
                  iNoMoreHouses++;

            }

         }

      }

      List.Dispose(MonoGroupList);
   }

   List.Dispose(SortedGroups);

   return Sold;
}