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

More entries in Personal Blogs

More entries from DRAGONBALLVINTAGE

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Biomutant looks cool tho, may have to try that
  • Quincy @ Quincy:
    Usually when such a big title leaks the Temp will be the first to report about it (going off of historical reports here, Pokemon SV being the latest one I can recall seeing pop up here)
  • K3Nv2 @ K3Nv2:
    I still like how a freaking mp3 file hacks webos all that security defeated by text yet again
  • BigOnYa @ BigOnYa:
    They have simulators for everything nowdays, cray cray. How about a sim that shows you playing the Switch.
  • K3Nv2 @ K3Nv2:
    That's called yuzu
    +1
  • BigOnYa @ BigOnYa:
    I want a 120hz 4k tv but crazy how more expensive the 120hz over the 60hz are. Or even more crazy is the price of 8k's.
  • K3Nv2 @ K3Nv2:
    No real point since movies are 30fps
  • BigOnYa @ BigOnYa:
    Not a big movie buff, more of a gamer tbh. And Series X is 120hz 8k ready, but yea only 120hz 4k games out right now, but thinking of in the future.
  • K3Nv2 @ K3Nv2:
    Mostly why you never see TV manufacturers going post 60hz
  • BigOnYa @ BigOnYa:
    I only watch tv when i goto bed, it puts me to sleep, and I have a nas drive filled w my fav shows so i can watch them in order, commercial free. I usually watch Married w Children, or South Park
  • K3Nv2 @ K3Nv2:
    Stremio ruined my need for nas
  • BigOnYa @ BigOnYa:
    I stream from Nas to firestick, one on every tv, and use Kodi. I'm happy w it, plays everything. (I pirate/torrent shows/movies on pc, and put on nas)
  • K3Nv2 @ K3Nv2:
    Kodi repost are still pretty popular
  • BigOnYa @ BigOnYa:
    What the hell is Kodi reposts? what do you mean, or "Wut?" -xdqwerty
  • K3Nv2 @ K3Nv2:
    Google them basically web crawlers to movie sites
  • BigOnYa @ BigOnYa:
    oh you mean the 3rd party apps on Kodi, yea i know what you mean, yea there are still a few cool ones, in fact watched the new planet of the apes movie other night w wifey thru one, was good pic surprisingly, not a cam
  • BigOnYa @ BigOnYa:
    Damn, only $2.06 and free shipping. Gotta cost more for them to ship than $2.06
  • BigOnYa @ BigOnYa:
    I got my Dad a firestick for Xmas and showed him those 3rd party sites on Kodi, he loves it, all he watches anymore. He said he has got 3 letters from AT&T already about pirating, but he says f them, let them shut my internet off (He wants out of his AT&T contract anyways)
  • K3Nv2 @ K3Nv2:
    That's where stremio comes to play never got a letter about it
  • BigOnYa @ BigOnYa:
    I just use a VPN, even give him my login and password so can use it also, and he refuses, he's funny.
  • BigOnYa @ BigOnYa:
    I had to find and get him an old style flip phone even without text, cause thats what he wanted. No text, no internet, only phone calls. Old, old school.
    K3Nv2 @ K3Nv2: @BigOnYa...