Learned C here's my version of Hello,World!

#include <stdio.h>

int main() {

printf("Thank you @drenal couldn't do it without ya!");
return 0;
}

Comments

G
Or there is this variant:
Code:
#include <stdio.h>
#include <string.h>
int main()
{
    const char thanks[] = "Thank you @drenal couldn't do it without ya!";
    for (int i = 0; i <= (strlen(thanks) - 1); i++)
        putchar(thanks[i]);
    return 0;
}
I would recommend purchasing a book. In my experience, free web-based tutorials are a bad way to go because the creators aren't making money off of it (usually), so they have no motivation. When an author knows they are going to be making money, they want to make it the best they can and as appealing as possible for the most income.
 
  • Like
Reactions: 1 person
@blujay I don't know about C. but you use "char" as a type of array? Isn't char supposed to be used with that, chars? Lol
 
G
There is no 'string' variable. char is the identifier for character, which in turn will make strings. Now, I could assign each individual character of the array by saying this:
Code:
const char thanks[] = {'T', 'h', 'a', 'n', 'k', ' ', 'y', 'o', 'u', [etc]};
However that is unreasonable.
 
  • Like
Reactions: 3 people
I see! That was the problem. I didn't knew that. I used string name[] (or whatever type I need) to create arrays. Now it makes sense. Thank you!
 
  • Like
Reactions: 1 person
G
By defining type string as a char* this code also works:
Code:
#include <stdio.h>
#include <string.h>
typedef char* string;
int main()
{
    const string thanks = "Thank you @drenal couldn't do it without ya!";
    for (int i = 0; i <= (strlen(thanks) - 1); i++)
        putchar(thanks[i]);
    return 0;
}
However it still just shows that a string is a character array (char* name is the same as char name[])
 
  • Like
Reactions: 1 person
Now, if you haven't created an array (at least not using []), how is the FOR supposed to run through the supposed array you tell him to run (even if it doesn't exist)?
And making var types looks great lol
 
G
In C, the following two statements function the exact same:
Code:
putchar(thanks[i]);

and 

putchar(*(thanks + i));
That just shows that pointers and arrays are the exact same thing, just arrays make things more legible.

Defining an array as const char* name and const char name[] end up the exact same. It declares name to be a pointer to a character value.
 
  • Like
Reactions: 1 person
Ookay. I think I understand. Then, when would you use a "pointer" (that if I understood correctly, they were represented with a [type]*) instead of an array and viceversa? I mean, they should have a situational difference, or they have not?

Thank you for your answers, by the way.
 
I am not sure if that was sarcasm or something, but if it wasn't, everything that has been showed here looks "difficult" to understand if you have never tried to program, but in fact, they are quite easy -and very logical too-.

I'm not a pro programmer nor anything similar, in fact, I have studied 1 year of Java and now I'm learning PHP and JS. The three lenguages are kind of similar in some aspects, for example, the three of them, use the (almost) same loop structure (FOR, IF, WHILE...). It's not that hard if you have time and try to understanding.

Now, that being said, I don't know many things about programming, and of course, there are MANY that are hard to understand and use, and that's why programmers -in many cases- need more credits and kudos than they get.

That's my humble opinion.
 

Blog entry information

Author
DRAGONBALLVINTAGE
Views
538
Comments
62
Last update

More entries in Personal Blogs

More entries from DRAGONBALLVINTAGE

General chit-chat
Help Users
  • Xdqwerty @ Xdqwerty:
    updated ship of harkinian, gonna install some hd texture pack
  • Xdqwerty @ Xdqwerty:
    I might download rayman revolution for my ps3
  • BigOnYa @ BigOnYa:
    I may try the new ram site, and download more RAM to my Switch. Not sure if ddr3 is the right ram
    for it tho. Edit- no it uses floppy Ram, just like @AncientBoi
    +1
  • Xdqwerty @ Xdqwerty:
    aeiou
  • BigOnYa @ BigOnYa:
    And sometimes Z
  • SylverReZ @ SylverReZ:
    @K3Nv2, MAGA supporters be wearing tin foil hats lol.
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, whats maga?
  • BigOnYa @ BigOnYa:
    It stands for Maniacs Against General Acceptance
    +1
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, people rejecting general consensus about stuff?
    +1
  • BigOnYa @ BigOnYa:
    Yup, nuh its really just Trump followers
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, im not american so i dont care about trump
    +1
  • Xdqwerty @ Xdqwerty:
    or us elections
  • BigOnYa @ BigOnYa:
    Me niether, us north Koreans don't care
  • Xdqwerty @ Xdqwerty:
    good night
  • BakerMan @ BakerMan:
    i don't care either, even if i'm american
  • BakerMan @ BakerMan:
    truth be told, i agree with psi, i dislike both candidates, but i'd probably vote trump simply because the economy was better during his presidency
    +1
  • AngryCinnabon @ AngryCinnabon:
    Just be careful, if trump ends up winning and using project 2025 America might really change...for the worse.
  • AngryCinnabon @ AngryCinnabon:
    I'm not american and even that sends shivers down my spine.
  • AngryCinnabon @ AngryCinnabon:
    anything that offers trump an opportunity to become an actual dictator
    is bad in my book, i could care less if it wasn't for that...
  • K3Nv2 @ K3Nv2:
    Canada: America's Russia
  • NinStar @ NinStar:
    people are so dramatic that I can't even tell if they are being serious
  • Psionic Roshambo @ Psionic Roshambo:
    Why so serious!
  • Psionic Roshambo @ Psionic Roshambo:
    @BakerMan, yeah that's about the only reason I would vote for Trump over Biden.
  • Psionic Roshambo @ Psionic Roshambo:
    In my opinion on all other factors they are pretty much the same.
    Psionic Roshambo @ Psionic Roshambo: In my opinion on all other factors they are pretty much the same.