[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
C Help
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 33
Thread images: 2
File: ansi-c.jpg (14 KB, 250x284) Image search: [Google]
ansi-c.jpg
14 KB, 250x284
So, basically, I'm in 1st year of CS, and in the first semester I learned Haskell, and it was awesome.
Now in the 2nd semester I'm learning C and also have to make a project on it, but now I'm running tight on the deadline and don't know almost anything of C. Can you recommend books/tutorials/ whatever that can help me learn this from the beggining. Thanks
>>
>>53328158
Just try to code with it. That's the best way to learn.
>>
>>53328210
It's kind hard to do ti when I don't know how to do it. For example, I've got to make this game, and the first step is to make a function that shuffles and gives cards. kek how do I do that?
>>
>>53328275
google: shuffle array
>>
What sort of magical program offers c and haskell first year?
>>
>>53328275
#include <stdlib.h>

void shuffle(int *array, size_t n)
{
if (n > 1)
{
size_t i;
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
>>
>>53328275

first just think about what your program will do without any regard to the language:

define array of cards

for (index through our array) {
generate new array of random numbers 1-52 with 52 elements, no repeats
}

assign each element of the card's array to the element of the random generated array with the number of its index

output results

>>
>>53328918
>if (n > 1)
> {
Perfect example of stupid "optimization".
>>
>>53328918
What's the difference between a regular int, and size_t?
>>
>>53328158
>have to make a project on it
What exactly does this project have to do?
>>
>>53328275
>>53329384
read the K&R
>>
File: 1446861464355.jpg (101 KB, 401x480) Image search: [Google]
1446861464355.jpg
101 KB, 401x480
>>53328158
What is the project?
I can help you.
>>
>>53329384
>>53329537
The project is to develop a game based on Big Deuce - https://www.pagat.com/climbing/bigtwo.html

The first step like I said is to write a function that shuffles and gives cards.
>>
>>53328702
One of the best in Portugal and Europe
>>
>>53329361
Nothing really. An int is a general purpose primitive type (use it for pretty much anything) which can be signed or unsigned, whereas a size_t is an unsigned int, typically meant to hold an index of an array
>>
>>53328158
As with all other situations, break it down into smaller problems.

First,
>How to write and build hello world in TARGET_LANG
>How to get input in TARGET_LANG

Random example:
Let's say you need to make a Poker game.
The next set of questions become
>What are the rules of poker?
>What are the smallest parts of the game of poker?

So Poker has cards, and each player has a collection of those cards, and there is a Deck of cards from which players get their cards. The deck is strictly defined as well (52 unique cards.)

That leads to the next question
>How can I represent/store a Card in this language? What data type or language construct is appropriate?
>How can I represent a collection of Cards in this language?

And so on. Break things down. Use google for "how do I do SimpleThingX in TARGET_LANG" questions.
>>
>>53328158
bullshit Haskell is taught at unis
anyways, how far does it go? monads?
also, I agree, C a shit, it's so imperative, but not as dumb as java though
>>
>>53328275
lamo do you actually "know" haskell?

if u did u wouldnt be asking these questions. nice troll
>>
>>53333571
This post is so stupid it made me a little angry.
>>
how would u do it in Haskell?
would you make the cards a data type?
surely you have to map 1-52 to all the cards right?
any other take goys?
>>
>>53333672
pls tell me how a 1950s lang is good, C is outdated, only used for embedded systems, which nobody uses
>>
>>53333714
you need to make your bait more subtle
>>
>>53333753
yeah, I was gonna go with
>rust is better at embedded systems
>>
>>53333714
It is used for more than embedded systems.

I write kernel drivers and modules for Linux for a living and do it all in C.

Also pretty much every other language or framework is built using C.

C is what allows you to write shit in Python or Java or whatever else you use.

C is portable assembly and assembly is at the heart of what the CPU works with so it isn't going to go away until something better than assembly comes along.

Sure you wouldn't write your web app or even a desktop app in pure C but for the guys of what makes pretty much everything work in the world you do use C. The routers that run the internet. The kernel that runs your desktop and mobile OS. The firmware in your appliances. It is all in C.Pretty much the only big area that C isn't king is financial where it is fucking COBOL of all things.
>>
>>53333810
but it's all part of the past
now, bigger languages like java are dominating because the internet is more important than operating systems already developed
learn Java and Java libs or you'll be out of work, kid
>>
>>53333896
Yeah Java has a place too. Most of the big languages are important in their own way.

You want to know how Java is developed though? yup in C. So if you want Java to keep improving you are gonna need C programmers ;)
>>
>>53333915
honestly, I see the worth of C, but its worth is only historical now.
I heard C++ is a better C anyways.
>>
>>53333810
How do I get into that, what's the pay?
What libs to learn, what to learn, pls help?
>>
>card game
>C

enjoy your brain cancer
>>
>>53333571
Yeah monads, but you gotta start somewhere.
Don't tell me Java is stupid cuz it's almost all I'm gonna do in the 2nd year. Fuck dis, can I pls learn proper programming languages?
>>
>>53333597
I didn't claim I know Haskell, but I do know the basics. And for that second shit, what that has to do with it? I fucking dare you to pick a language you don't almost nothing about and just do the same things you do on a language you do pretty well. Sucka
>>
>>53334459
if you don't understand the very basic concept of 'a list' and 'sorting a list' then I can see why it would be hard for you.

too bad you haven't figured out programming languages aren't about syntax :)
>>
>>53333571
At my uni we learnt Haskell in the optional bonus lecture in the first semester. Well not "we" exactly, I was a lazy fuck who didn't attend lectures in general. But yeah they went pretty deep as far as I saw.
Thread replies: 33
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.