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
522
Comments
62
Last update

More entries in Personal Blogs

More entries from DRAGONBALLVINTAGE

General chit-chat
Help Users
  • No one is chatting at the moment.
  • K3Nv2 @ K3Nv2:
    Thanks for signing up at LinusTechTips
  • QuarterCut @ QuarterCut:
    holey shmoley!
  • BigOnYa @ BigOnYa:
    Your credit card has been charged. Thank you.
  • K3Nv2 @ K3Nv2:
    Your screwdriverPlus will arrive in three weeks
    +1
  • QuarterCut @ QuarterCut:
    K64_Waddle_Dee_Artwork_1.jpg

    my reaction to such information
    +2
  • BigOnYa @ BigOnYa:
    Press 1 for English. Press 2 for Pig Latin. Or press 3 to speak to a representative.
  • BakerMan @ BakerMan:
    guys, i need help, i got into an argument about what genre radioactive is, and i forgot who made it
  • Sicklyboy @ Sicklyboy:
    @BakerMan, Imagine Dragons
  • Sicklyboy @ Sicklyboy:
    Dragon deez nuts across yo face GOTEEM
  • Sicklyboy @ Sicklyboy:
    lmao now I realize that was probably the joke in the first place
    +1
  • BakerMan @ BakerMan:
    IMAGINE DRAGON DEEZ NUTS ACROSS YO- FUCK HE BEAT ME TO IT
  • BigOnYa @ BigOnYa:
    You have selected 4 - Death by Snu Snu, please stand by...
    +1
  • BakerMan @ BakerMan:
    lucky bastard
    +1
  • Sicklyboy @ Sicklyboy:
    hahahaha I'm half way through a bag off my Volcano and my tolerance is way down because I haven't been smoking much lately, so I was a little slow to catch that that was what your angle was 🤣🤣
    +1
  • Sicklyboy @ Sicklyboy:
    Also I was just excited to know a music reference for once (I am the LAST person in the world that you want on your trivia team)
    +2
  • K3Nv2 @ K3Nv2:
    Bummer webos 7.4 isnt working with dejavuln-autoroot
  • Sicklyboy @ Sicklyboy:
    PS4 right? I think that's what mine's on. Or 5.6, maybe.
  • K3Nv2 @ K3Nv2:
    [!] Installation failed (devmode_enabled not recognized)
  • K3Nv2 @ K3Nv2:
    0.5 seemed to work whatever lol i wont bitch
  • Alysh_Graham @ Alysh_Graham:
    Hehehe
    Alysh_Graham @ Alysh_Graham: Hehehe